在Python中获取文件属性(隐藏,只读,系统,存档) [英] Get file attributes (hidden, readonly, system, archive) in Python
本文介绍了在Python中获取文件属性(隐藏,只读,系统,存档)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
刚开始学习Python.如何在Python中获取文件属性的状态?我知道os.chmod(fullname, stat.S_IWRITE)
删除只读属性,但是如何在不更改状态的情况下获取状态?我需要获取"hidden"
,"system"
,"readonly"
,"archive"
Just started learning Python. How can i get a status of file's attributes in Python? I know that os.chmod(fullname, stat.S_IWRITE)
delete readonly attribute, but how can i get status without changing it? I need to get all of the attributes of "hidden"
, "system"
, "readonly"
, "archive"
推荐答案
您可以像这样直接使用Windows API
You can use directly the Windows API like that
import win32con
import win32api
attrs = win32api.GetFileAttributes(filepath)
attrs & win32con.FILE_ATTRIBUTE_SYSTEM
attrs & win32con.FILE_ATTRIBUTE_HIDDEN
这篇关于在Python中获取文件属性(隐藏,只读,系统,存档)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文