Entry
How can you check on the status of a file's "archive" bit, on DOS-type platforms
Jul 15th, 2000 06:05
unknown unknown, Barry Pederson, Alex Martelli
On Win32, with Hammond's extensions:
PythonWin 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on
win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Portions Copyright 1994-1999 Mark Hammond (MHammond@skippinet.com.au)
>>> from win32file import GetFileAttributes
>>> GetFileAttributes("C:/witha.txt")
32
>>> GetFileAttributes("C:/withouta.txt")
128
>>>
where witha.txt does have the A attribute and withouta.txt lacks it.
You can also use symbolic names for the constants:
>>> import win32file
>>> win32file.FILE_ATTRIBUTE_ARCHIVE
32
>>> win32file.FILE_ATTRIBUTE_NORMAL
128
>>>
Note that the 'normal' bits seems to be set if and only if no other
bits are set. Other attributes in the bitmask behave more normally,
i.e., they are bitwise-or'ed to give all attributes of the file.
For example, after making witha.txt read-only (still _with_ the A
attribute as well), we have:
>>> GetFileAttributes("C:/witha.txt")
33
>>> win32file.FILE_ATTRIBUTE_READONLY
1
>>>
I.e., the attributes of the file are the bitwise-or of archive and
readonly. So, if you only want to test for archive, and don't care
about the others, you'll bitwise-and GetFileAttributes' result with
FILE_ATTRIBUTE_ARCHIVE, rather than testing for equality!