国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python判斷windows隱藏文件的方法

2020-02-23 05:14:30
字體:
來源:轉載
供稿:網友

1. 通過windows attrib 命令獲取文件隱藏屬性
代碼如下:Syntax
      ATTRIB [ + attribute | - attribute ] [pathname] [/S [/D]]

Key
     +    : Turn an attribute ON
     -    : Clear an attribute OFF

 pathname : Drive and/or filename e.g. C:/*.txt
    /S    : Search the pathname including all subfolders.
    /D    : Process folders as well

   attributes:

        R  Read-only (1)
        H  Hidden (2)
        A  Archive (32)
        S  System (4)

   extended attributes:
        E  Encrypted
        C  Compressed (128:read-only)
        I  Not content-indexed
        L  Symbolic link/Junction (64:read-only)
        N  Normal (0: cannot be used for file selection)
        O  Offline
        P  Sparse file
        T  Temporary


2. 隱藏屬性值及其含義 
Constants - the following attribute values are returned by the GetFileAttributes function:

代碼如下:
FILE_ATTRIBUTE_READONLY = 1 (0x1)
FILE_ATTRIBUTE_HIDDEN = 2 (0x2)
FILE_ATTRIBUTE_SYSTEM = 4 (0x4)
FILE_ATTRIBUTE_DIRECTORY = 16 (0x10)
FILE_ATTRIBUTE_ARCHIVE = 32 (0x20)
FILE_ATTRIBUTE_NORMAL = 128 (0x80)
FILE_ATTRIBUTE_TEMPORARY = 256 (0x100)
FILE_ATTRIBUTE_SPARSE_FILE = 512 (0x200)
FILE_ATTRIBUTE_REPARSE_POINT = 1024 (0x400)
FILE_ATTRIBUTE_COMPRESSED = 2048 (0x800)
FILE_ATTRIBUTE_OFFLINE = 4096 (0x1000)
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192 (0x2000)
FILE_ATTRIBUTE_ENCRYPTED = 16384 (0x4000)
For example, a file attribute of 0x120 indicates the Temporary + Archive attributes are set (0x100 + 0x20 = 0x120.)
3. python 通過 win32api 獲取文件隱藏屬性
python 官網對 win32API 的簡單說明 https://www.python.org/download/windows/
下載地址 http://sourceforge.net/projects/pywin32/

代碼如下:import win32file
·
filenames = [r'D:/test',
             r'D:/test/$RECYCLE.BIN',
             r'D:/test/.file_test.py.swp',
             r'D:/test/file_test.py']

for filename in filenames:
    print '%4d, %s' %(win32file.GetFileAttributesW(filename), filename)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邮箱| 池州市| 金门县| 哈密市| 克山县| 吉安县| 郎溪县| 中西区| 阳谷县| 荔浦县| 石台县| 红河县| 平度市| 九龙县| 乌拉特前旗| 东台市| 英德市| 五家渠市| 靖安县| 稷山县| 桐庐县| 景东| 聂拉木县| 屏边| 阳春市| 博爱县| 新沂市| 台湾省| 饶平县| 伊金霍洛旗| 桐乡市| 天柱县| 三穗县| 齐河县| 慈溪市| 铁岭市| 扎鲁特旗| 临清市| 景德镇市| 江阴市| 吉隆县|