如何递归创建目录? [英] How can I create directories recursively?
本文介绍了如何递归创建目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有递归创建目录的 Python 方法?我有这个路径:
Is there a Python method to create directories recursively? I have this path:
/home/dail/
我想创建
/home/dail/first/second/third
我可以递归执行还是必须一个接一个地创建一个目录?
Can I do it recursively or I have to create one directory after the other?
同样的事情:
chmod 和 chown 我可以在不为每个文件/目录分配权限的情况下递归执行吗?
chmod and chown can I do it recursively without assign permissions for each file/dir?
推荐答案
os.makedirs
正是您所需要的.对于 chmod
或 chown
,您必须使用 os.walk
并自己在每个文件/目录上使用它.
os.makedirs
is what you need. For chmod
or chown
you'll have to use os.walk
and use it on every file/dir yourself.
这篇关于如何递归创建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文