我正在使用python 3.7和以下命令创建一个在Linux上运行而不在Windows上运行的目录:
try:
#shutil.rmtree('../../dist')
os.makedirs('../../dist')
except OSError as e:
print("fffffffffffffffffffffffffffff")
print(e)
if e.errno != errno.EEXIST:
raise
这是我在Windows上运行时遇到的错误:
fffffffffffffffffffffffffffff
[WinError 183] Cannot create a file when that file already exists:
'../../dist'
并且根本没有dist文件夹,我不知道该错误是什么
任何的想法?
根据OP的要求评论为答案:
这里的问题是你提供了一个相对于脚本的路径,但相对路径是相对于进程的工作目录解释的,这通常与脚本位置完全不同。该目录已经相对于工作目录存在,但您正在查看相对于脚本的路径,并且(正确地)在那里找不到任何内容。
如果必须相对于脚本创建目录,请将代码更改为:
scriptdir = os.path.dirname(__file__)
# abspath is just to simplify out the path so error messages are plainer
# while os.path.join ensures the path is constructed with OS preferred separators
newdir = os.path.abspath(os.path.join(scriptpath, '..', '..', 'dist'))
os.makedirs(newdir)