从此列表中将所有文件和文件夹递归设置为777 [英] Recursively set all files and folders to 777 from this list
本文介绍了从此列表中将所有文件和文件夹递归设置为777的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试了无休止地寻找解决方案,但是似乎找不到答案.
I've tried endlessly searching for a solution to this, but couldn't seem to find out.
我有一个路径列表:
dirToModify = ['includes/','misc/','modules/','scripts/','themes/']
我想遍历每个列表项(在这种情况下为目录),并将所有文件和目录设置为777
I want to loop through each list-item (a dir in this case) and set all files and dirs to 777
我已经对以下文件执行了此操作:
I've done this for files like:
for file in fileToModify:
os.chmod(file, 0o777)
但是似乎无法找到一种递归地对文件夹执行此操作的好方法.
But can't seem to figure out a good way to do this recursively to folders.
任何人都可以帮忙吗?
推荐答案
您可以遍历要修改的目录,然后使用os.walk
遍历每个目录中的所有目录和文件,像这样:
You can iterate through the directories you'd like to modify, then use os.walk
to iterate over all of the directories and files in each of these directories, like so:
for your_dir in dirs_to_modify:
for root, dirs, files in os.walk(your_dir):
for d in dirs:
os.chmod(os.path.join(root, d), 0o777)
for f in files:
os.chmod(os.path.join(root, f), 0o777)
这篇关于从此列表中将所有文件和文件夹递归设置为777的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文