国产探花免费观看_亚洲丰满少妇自慰呻吟_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)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 孟州市| 重庆市| 陆丰市| 肥乡县| 巴塘县| 高陵县| 噶尔县| 普安县| 贡山| 清河县| 麟游县| 铜陵市| 连山| 颍上县| 马公市| 淮南市| 蓬安县| 阿拉善左旗| 九寨沟县| 江西省| 桑植县| 绥江县| 城固县| 汉中市| 福贡县| 随州市| 寻乌县| 当涂县| 淮南市| 富蕴县| 边坝县| 西乌珠穆沁旗| 安仁县| 肥乡县| 周口市| 颍上县| 东至县| 伊春市| 洛川县| 宁南县| 德安县|