in reply to How to find the create time of a file under MS

stat[10] gives you the creation time of the file (on Win32, at least), while the output of dir gives you the last modified time. Try the following and compare it to the file properties in explorer:
#!/usr/bin/perl -w use strict; #use diagnostics; use warnings; use POSIX; my $file = $ARGV[0] || 'a.pl'; my @t = stat($file); print "Accessed: ", strftime("%A, %B %d, %Y, %H:%M:%S",localtime($t[8] +)), "\n"; print "Modified: ", strftime("%A, %B %d, %Y, %H:%M:%S",localtime($t[9] +)), "\n"; print "Created: ", strftime("%A, %B %d, %Y, %H:%M:%S",localtime($t[10] +)), "\n";

Update: added dir and last modified above, emphasized 'on Win32'

Update 2.5: Okay, thunders made me curious. I dug into the perl source. Perl's stat (built with Visual C) is implemented using the stat or wstat function. According to MS, these functions return st_ctime, which is the "Time of creation of file. Valid on NTFS but not on FAT formatted disk drives." This is what stat[10] returns.

Also, if you move a file across file systems (from c: to d:, for example) the creation time changes.

Replies are listed 'Best First'.
Re: Re: How to find the create time of a file under MS
by thunders (Priest) on Jul 16, 2002 at 15:54 UTC
    stat[10] is ctime which is literally inode change time. Thing is, in my test at least on Windows this appears to return creation time. On Unix something as simple as moving a file will update this value, as will security related changes like chgrp. not the case on Windows, the value stays the same, and appears to be the actual file creation time.
Re: Re: How to find the create time of a file under MS
by demerphq (Chancellor) on Jul 17, 2002 at 09:44 UTC
    Thanks very much.

    Im going to write to p5p to see if this is considered a feature and if so ill provide them a patch for the documentation.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

Re: How to find the create time of a file under MS
by Anonymous Monk on Jun 14, 2004 at 13:48 UTC
    How can I SET the values discussed here using Perl, e.g. if I move a file from one partition to another but want it to have the original (file's) time stamp?