我正在尝试在python中创建多个目录,但它说该文件不存在,即使我刚刚在代码上面创建它,下面的帮助将非常感激。
import os
import shutil
# err
if os.path.isdir(r'\Users\Oran\Documents\Sync\Files\Projects/testProject'):
shutil.rmtree(r'\Users\Oran\Documents\Sync\Files\Projects/testProject')
# Main
os.chdir(r'\Users\Oran\Documents\Sync\Files\Projects')
os.mkdir('testProject')
os.chdir('testProject')
f = open("index.html", "wt")
dir_names = ["assets", "css"]
for x in (dir_names):
os.mkdir(x)
os.chdir('css/')
f = open("index.css", "wt")
os.chdir('assets/')
dir_names = ["img", "css", "js"]
for x in (dir_names):
os.mkdir(x)
os.chdir('js/')
f = open("index.js", "wt")
[Running] python
"c:\Users\Oran\Documents\Sync\Files\Projects\PYProjetCreator\index.py"
Traceback (most recent call last):
File
"c:\Users\Oran\Documents\Sync\Files\Projects\PYProjetCreator\index.py", line
24, in <module>
os.chdir('assets/')
FileNotFoundError: [WinError 2] The system cannot find the file specified:
'assets/'
[Done] exited with code=1 in 0.089 seconds