# https://docs.python.org/3/library/pathlib.html?highlight=pathlib#correspondence-to-tools-in-the-os-module


(BlogVenv) C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog>python manage.py shell --settings=Blog.settings.settings_dev
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
>>> import os, shutil

# 중복생성시도 해도 에러없다 (exist_ok=True)
>>> os.makedirs(os.path.join(settings.UPLOAD_ROOT, "TEST"), exist_ok=True)
>>> os.makedirs(os.path.join(settings.UPLOAD_ROOT, "TEST"), exist_ok=True)

# 중복삭제시도 하면 에러 발생한다.
>>> os.removedirs(os.path.join(settings.UPLOAD_ROOT, "TEST"))
>>> os.removedirs(os.path.join(settings.UPLOAD_ROOT, "TEST"))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog\BlogVenv\lib\os.py", line 239, in removedirs
    rmdir(name)
FileNotFoundError: [WinError 2] 지정된 파일을 찾을 수 없습니다: 'C:\\Work\\Software\\eclipse-jee-2019-12-R-win32-x86_64\\workspace\\Blog\\media\\upload\\TEST'

# 중복삭제시도 해도 에러 없다.
>>> shutil.rmtree(os.path.join(settings.UPLOAD_ROOT, "TEST"), ignore_errors=True)
>>> shutil.rmtree(os.path.join(settings.UPLOAD_ROOT, "TEST"), ignore_errors=True)


# 현재 path
>>> os.getcwd()

# directory list
>>> os.listdir()

# directory or file 존재여부 확인
>>> os.path.exists(os.path.join(settings.UPLOAD_ROOT, "TEST"))
False
>>>

# directory 존재여부 확인
>>> os.path.isdir(os.path.join(settings.UPLOAD_ROOT, "TEST"))
False
>>>

# file 존재여부 확인
>>> os.path.isfile(os.path.join(settings.UPLOAD_ROOT, "TEST"))
False