Chmod问题使用python更改文件权限 [英] Chmod issue to change file permission using python
本文介绍了Chmod问题使用python更改文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望更改所有文件的文件权限,以便使用python脚本为目录中的所有用户执行读写操作。但是,在运行脚本后,当我通过右键单击检查文件权限时,它只显示我的权限,并且仅显示每个人具有读取权限的组的权限。我在以下脚本中有什么问题:
I am looking to change the file permission to all files to read write and execute for all the users in a directory using a python script. However, after running the script when I check the file permission doing the right click, it only shows the permissions for me and for the group everyone it only has read permission. Is there anything wrong I am doing in the following script:
import os
import pdb
for dirpath, dirnames, filenames in os.walk('M:\intra\EU'):
for filename in filenames:
path = os.path.join(dirpath, filename)
os.chmod(path, 0o777) # for example
推荐答案
我在这里找到了解决方案:)
I found a solution here :)
import win32security
import ntsecuritycon as con
import os
import pdb
userx, domain, type = win32security.LookupAccountName ("", "Everyone")
directory='M:\intra\EU'
for dirpath, dirnames, filenames in os.walk('M:\intra\EU'):
for FILENAME in filenames:
sd = win32security.GetFileSecurity(directory+'\\'+FILENAME, win32security.DACL_SECURITY_INFORMATION)
dacl = sd.GetSecurityDescriptorDacl() # instead of dacl = win32security.ACL()
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_ALL_ACCESS, userx)
sd.SetSecurityDescriptorDacl(1, dacl, 0)
win32security.SetFileSecurity(directory+'\\'+FILENAME, win32security.DACL_SECURITY_INFORMATION, sd)
这篇关于Chmod问题使用python更改文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文