2024-06-08 18:09:27 发布
网友
有没有办法用Python隐藏文件夹/文件?
我在做一个庞大的项目(漏洞扫描器)。这个项目创建了很多文件和文件夹。因此,问题是,有没有办法制作一个隐藏文件和文件夹的脚本?
如果这是针对Windows的:
http://code.activestate.com/recipes/303343/
总结: 导入win32api、win32con、os win32api.SetFileAttributes(文件名,win32con.FILE_ATTRIBUTE_HIDDEN)
如果是Unix:
filename=“.”+文件名
对于文件名中的文件地址,使用r作为前缀,因为地址包含反斜杠。。。例如r“c:…\file”
如果不想麻烦使用pywin32,可以使用标准库中的ctypes调用SetFileAttributes。
ctypes.windll.kernel32.SetFileAttributesW(path, 2)
path必须是unicode字符串类型,因为这是SetFileAttributes的unicode版本。常量2来自this page(文件属性隐藏)。我想没有办法从ctypes中得到好的常量名称,所以您必须自己查找它们。
path
import tempfile
请参阅documentation。
这里“hidden file”是指"The file is readable and writable only by the creating user ID.",也就是说,意思是“hide file from other users”。
如果这是针对Windows的:
http://code.activestate.com/recipes/303343/
总结: 导入win32api、win32con、os win32api.SetFileAttributes(文件名,win32con.FILE_ATTRIBUTE_HIDDEN)
如果是Unix:
filename=“.”+文件名
对于文件名中的文件地址,使用r作为前缀,因为地址包含反斜杠。。。例如r“c:…\file”
如果不想麻烦使用pywin32,可以使用标准库中的ctypes调用SetFileAttributes。
path
必须是unicode字符串类型,因为这是SetFileAttributes的unicode版本。常量2来自this page(文件属性隐藏)。我想没有办法从ctypes中得到好的常量名称,所以您必须自己查找它们。请参阅documentation。
这里“hidden file”是指"The file is readable and writable only by the creating user ID.",也就是说,意思是“hide file from other users”。
相关问题 更多 >
编程相关推荐