gpt4 book ai didi

python - python中文件的权限更改

转载 作者:太空狗 更新时间:2023-10-29 17:38:35 25 4
gpt4 key购买 nike

我想更改当前目录树中所有文件的文件权限。我正在尝试打开每个目录并打开文件并使用 os.chmod() 更改权限,但出现错误。

import os
import stat

for files in os.walk('.'):
os.chmod(files,stat.S_IXGRP)

我得到的错误是:

File "delhis.py", line 4, in ? os.chmod(files,stat.S_IXGRP) TypeError: coercing to Unicode: need string or buffer, tuple found

最佳答案

您错误地使用了 os.walk

for dirpath, dirnames, filenames in os.walk('.'):
for filename in filenames:
path = os.path.join(dirpath, filename)
os.chmod(path, 0o777) # for example

关于python - python中文件的权限更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7228296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com