Set archive bit on files in a directory

import win32file
import win32con
import os

def togglefileattribute(filename, fileattribute, value):
    """Turn a specific file attribute on or off, leaving the other
    attributes intact.
    bitvector = win32file.GetFileAttributes(filename)
    if value:
        bitvector |= fileattribute
        bitvector &= ~fileattribute
    win32file.SetFileAttributes(filename, bitvector)

# Sample usage:
for file in os .listdir(r'C:\Temp\doc'):
    file = os.path.join(r'C:\Temp\doc\%s'%file)
    togglefileattribute(file, win32con.FILE_ATTRIBUTE_ARCHIVE, False)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.