Setting file creation date

Samuel Schulenburg samschul at pacbell.net
Fri Aug 10 20:37:02 EDT 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message news:<9l147s0tk3 at enews2.newsguy.com>...
> "Roman Suzi" <rnd at onego.ru> wrote in message
> news:mailman.997454355.12463.python-list at python.org...
> > On Fri, 10 Aug 2001, Alex Martelli wrote:
> >
> > >"Fredrik Seehusen" <fse at npt.no> wrote in message
> > >news:e77b4645.0108100226.4cfaf671 at posting.google.com...
> > >> Hello,
> > >>
> > >> How do I set the creation date when opening a file, or override the
> > >> creation date of a given file (... if it is possible in python)?
> > >>
> > >> This has to be done in Windows NT by the way :(
> > >
> > >os.utime lets you set the accessed and modified dates, but I
> > >don't think NT lets you change creation-date -- you'd have to
> > >change your computer's date, create a new file copying the
> > >old one, etc, etc, I suspect.
> >
> > Sorry for my total ignorance of NT, but AFAIK UNIX/Linux do not
> > have file creation date stored:
> 
> True; the 'c' stands for 'change' (to status), not for 'creation',
> on unix-like filesystems.
> 
> > Also I remember, Macintosh had file creation time stored,
> > but Windows 9x store only two times (probably mtime and ctime).
> 
> Wrong.  API GetFileTime correctly returns all three times
> (creation, last access, last write) on both NT and 9x and on
> both NTFS and FAT filesystems (the issue with the latter
> is the resolution of 2 seconds:-).
> 
> Which reminds me, SetFileTime lets you change those, and
> I don't know why win32file (part of the win32api) still does
> not make that call available according to the latest manual
> at URL [a single line, some sw will break it]:
> http://aspn.activestate.com/ASPN/Python/Reference/Products/ActivePython/Pyth
> onWin32Extensions/win32file.html
> 
> Should be a C extension of a few lines, worst case.  Much
> simpler/faster than the rigmarole of change-date/copy-file/&c
> which I previously suggested.  Maybe calldll.pyd can help.
> 
> > atime and mtime are quite easy to change, and the nature
> > of ctime is more subtle.
> >
> > So, I wonder where creation date is used and how it survives
> > archiving...
> 
> On NT?  It survives perfectly and it's quite useful, because the
> *modification* time may happen to be bogus while the creation
> time is often more reliable.
> 
> 
> Alex


Windows NT and WIndows200 support the following API cals:
GetFileInformationByHandle(hFile,&lpFileInformation);
SetFileAttributes(&PathString[0],lpFileInformation.dwFileAttributes);

With these two function, you can set the file attributes.
If the Pywin32 API calls do not support these function you will have
to use calldll, and windll that can be found  at

http://www.nightmare.com/software.html


Sam Schulenburg



More information about the Python-list mailing list