Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Getting the correct ctime for a file on Windows 10

by Veltro (Hermit)
on Jul 05, 2018 at 20:24 UTC ( [id://1217997]=note: print w/replies, xml ) Need Help??


in reply to Getting the correct ctime for a file on Windows 10

Hello Peppe757,

I've found another discussion regards this topic here. In this article there is an interesting link to Windows file times.

So as it seems ctime does not give what you want.

In the 'Windows file times' link the function GetFileTime is mentioned so looking for that I found the module Win32API::File::Time that has this function. So maybe you can try to use that one instead.

edit: I found another module that I actually like better. The module is called Win32::UTCFileTime. I have created the following sample program for testing:

use strict ; use warnings ; use DateTime ; use Win32::UTCFileTime qw(alt_stat $ErrStr) ; my $file = ".\\testFileTime2.pl" ; my @stats = alt_stat( $file ) or die "alt_stat() failed: $ErrStr\n" ; print "ctime = $stats[10]\n" ; my $dt = DateTime->from_epoch( epoch => $stats[10], time_zone => 'UTC' + ) ; print $dt->datetime . "\n" ; __END__ ctime = 1530825924 2018-07-05T21:25:24

edit 2: Anonymous Monk asked: "But is it any different from built-in stat". The answer can be found in the documentation: Note that the 11th element of the 13-element list returned by stat() is the creation time on Win32, not the inode change time as it is on many other operating systems. Therefore, neither Perl's built-in utime() function nor this replacement function set that value to the current time as would happen on other operating systems.

Replies are listed 'Best First'.
Re^2: Getting the correct ctime for a file on Windows 10
by Anonymous Monk on Jul 06, 2018 at 02:25 UTC
    But is it any different from built-in stat?
Re^2: Getting the correct ctime for a file on Windows 10
by Peppe757 (Initiate) on Jul 08, 2018 at 11:48 UTC
    Thank you for the response. The Image:ExifTool package is what I was looking for. I didn't realize that image files had their own set of metadata, including a timestamp which is different from the file datetime information returned by the stat function.
Re^2: Getting the correct ctime for a file on Windows 10
by Anonymous Monk on Jul 07, 2018 at 07:07 UTC

    The answer can be found in the documentation

    No, the answer can only be found by adding built-in stat usage to your program, and comparing

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1217997]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-23 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found