开发者

python mkdir to make folder with subfolder? [duplicate]

This question already has answers here: 开发者_JAVA技巧 mkdir -p functionality in Python [duplicate] (12 answers) Closed 4 years ago.

This works:

mkdir('folder')

but this doesn't

mkdir('folder/subfolder')

error:

WindowsError: [Error 3] The system cannot find the path specified: 'folder/subfolder'


Try os.makedirs instead, if you want to create a tree of directories in one call.


I tried the above on Linux using Python 2.6.6, but had to ensure that the string ended with a '/' (or '\', on Windows). E.g.

os.makedirs('folder/subfolder/')

Otherwise only 'folder' was created.


I think you want the os.makedirs() function, which can create intermediate directories.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜