"archive" bits (was FAQTS)

Alex Martelli alex at magenta.com
Sat Jul 15 05:15:46 EDT 2000


"Fiona Czuczman" <fiona at sitegnome.com> wrote in message
news:20000713214019.24273.qmail at synop.com...
    [snip]
> ## Unanswered Questions ########################################
> -------------------------------------------------------------
> How can you check on the status of a file's "archive" bit, on DOS-type
platforms
> http://www.faqts.com/knowledge-base/view.phtml/aid/4706
> -------------------------------------------------------------
> Barry Pederson

I had missed the original request.

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 at 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!


Alex






More information about the Python-list mailing list