1. Get file Hide properties via Windows attrib command
Copy Code code as follows:
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
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 is used for file selection)
O Offline
P Sparse File
T Temporary
2. Hide attribute values and their meanings
Constants-the following attribute values are returned by the GetFileAttributes function:
Copy Code code as follows:
File_attribute_readonly = 1 (0x1)
File_attribute_hidden = 2 (0x2)
File_attribute_system = 4 (0x4)
File_attribute_directory = (0x10)
File_attribute_archive = (0x20)
File_attribute_normal = 128 (0x80)
File_attribute_temporary = 256 (0x100)
File_attribute_sparse_file = 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, 0x120 indicates the temporary + Archive attributes are set (0x100 + 0x20 = 0x120.)
3. Python gets file hidden properties via Win32API
A brief description of Win32API in Python's official website https://www.python.org/download/windows/
Download Address http://sourceforge.net/projects/pywin32/
Copy Code code as follows:
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)
Run Result:
4. With operations (&) more intuitive to determine hidden files
Example code the following,& the result of the operation and the hidden attribute value, can be more intuitive to determine the file type.
Copy Code code as follows:
Import Win32file
Import Win32con
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:
File_flag = Win32file. GETFILEATTRIBUTESW (filename)
Is_hiden = File_flag & Win32con. File_attribute_hidden
Is_system = File_flag & Win32con. File_attribute_system
print '%4d,%s,%s,%s '% (File_flag, Is_hiden, is_system, filename)
Run Result: