Я нахожусь в своем рабочем каталоге, назовем его «WorkDir», вот он: C:\WorkDir
Я хочу создать:
Код: Выделить всё
newpath = 'C:\WorkDir\Video\Files'
if not os.path.exists(newpath):
os.makedirs(newpath)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\WorkDir\\Video'
Я также пытался использовать точку '.' для обозначения рабочего каталога, но это тоже не работает.
Ничто из этого не работает:
Код: Выделить всё
# raw string 'r'
newpath = r'C:\WorkDir\Video\Files'
if not os.path.exists(newpath):
os.makedirs(newpath)
Код: Выделить всё
# forward slashes
newpath = 'C:/WorkDir/Video/Files'
if not os.path.exists(newpath):
os.makedirs(newpath)
Код: Выделить всё
# period
newpath = '.\WorkDir\Video\Files'
if not os.path.exists(newpath):
os.makedirs(newpath)
Код: Выделить всё
# raw string
newpath = r'.\WorkDir\Video\Files'
if not os.path.exists(newpath):
os.makedirs(newpath)
FileNotFoundError: [WinError 2] The system cannot find the file specified: '.\\WorkDir'
Странно то, что я могу создать новый каталог прямо на диске C:, например:
Код: Выделить всё
# create new folder RandomFolder
newpath = r'C:\RandomFolder\Video\Files'
if not os.path.exists(newpath):
os.makedirs(newpath)
изменить: Полная ошибка:
Код: Выделить всё
FileNotFoundError Traceback (most recent call last)
in
2
3 if not os.path.exists(newpath):
----> 4 os.makedirs(newpath)
5
6 # could add number of records to file name too
~\Anaconda3\lib\os.py in makedirs(name, mode, exist_ok)
209 if head and tail and not path.exists(head):
210 try:
--> 211 makedirs(head, exist_ok=exist_ok)
212 except FileExistsError:
213 # Defeats race condition when another thread created the path
~\Anaconda3\lib\os.py in makedirs(name, mode, exist_ok)
219 return
220 try:
--> 221 mkdir(name, mode)
222 except OSError:
223 # Cannot rely on checking for EEXIST, since the operating system
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\WorkDir\\Video'
Редактировать 3: Решено. Это была «защита от программ-вымогателей» Windows. Python не разрешили запись в мой рабочий каталог.
Подробнее здесь: https://stackoverflow.com/questions/569 ... ot-find-th
Мобильная версия