Python judges windows hidden files/system files

Source: Internet
Author: User

In linux, files whose names start with periods (.) are hidden,

Win is determined by the file hiding attribute. Therefore,

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. Hide the property value and its meaning

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_normally = 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 uses win32api to obtain the file hiding attribute

Python official website for win32API simple description https://www.python.org/download/windows/

Http://sourceforge.net/projects/pywin32/

= [r filename  %(win32file.GetFileAttributesW(filename), filename)

Running result:

4. more intuitive judgment of hidden files with operations (&)

The sample code is as follows. The calculation result corresponds to the hidden property value, allowing you to more intuitively determine the file type.

= [r filename == file_flag &= file_flag & %(file_flag, is_hiden, is_system, filename)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.