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 else: 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)