On Aug 16, 2013, at 2:25 PM, John Aten wrote: > Hi all, > > I am working on a script to rename files after a formula (discussed here: > http://www.drbunsen.org/naming-and-searching-files-part-1/ ) . The formula > calls for an ID string that is constructed from the date and time the file is > created, of the format YYYMMDD_HHMMSS. The closest approximation of the file > creation date that I can find thus far is the inode change time returned by > the stat() function. I was under the impression that this would not be too > far off from the first save date, but from what I later read and my > experimentation, it seems VERY far off the vast majority of the time. The > inode change time is more often than not exactly the same as the last > modification time, and even when it's not it's nowhere close to the actual > date/time of the first time the file was saved. > > The ID string here serves two purposes: to make a unique identifier, and to > put the files in order by creation date and time. At the very least I figure > using the inode change time should produce unique identifiers, but I would > like to have chronological order if possible. Unfortunately, I am starting to > believe that this is not possible. I have files going back to the mid 1990's, > coming from various versions of Windows, as well as files produced over the > last few years natively on the Mac. Even the creation dates/times of the > native Mac files, as listed in the finder, seem radically incorrect. > > Does anyone know if this is possible? Or should I just accept the fact that > all dates before 8/2013 are suspect?
I would recommend the file modification time as your best bet. The times stored for each file are dependent upon the operating system and file system in use. Not all OS/FS systems are the same. Unix doesn't save the "creation time", when the file was originally created. However, Mac OS X and HFS+ do, and the creation times are maintained through moving and copying operations. I have files on my Mac that date back to 1984, which was several computers ago. I don't know about Windows. Unix saves the access time, file modification time, and inode change time. The inode change time is updated frequently, whenever the files metadata or content changes, Perl's stat() function returns these three, as do the -M, -A, and -C file tests. The problem on the Mac is getting at the creation time. You could try the MacOSX::File::Info module, which claims to do it, but that module hasn't been updated recently and it will not build on my 10.7.5 system. If you have Developer tools installed, then you can use the /Developer/Tools/GetFileInfo utility to print out the file creation time. You can call that from your Perl script with backquotes and capture the output: my @data = `/Developer/Tools/GetFileInfo $fullpath`; Then parse data for the 'created:' line. See this link for more information about file times in the various operating systems: <http://thomas.kiehnefamily.us/whats_in_a_creation_date> Good luck. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/