Dave's Brain

Browse - Programming Tips - How can I get a file's modified date?

Date: 2008may1
Language: perl
Keywords: moddate, modify, modified

Q.  How can I get a file's modified date?

A.  Here's how I do it:

# Does not use CPAN libraries, etc sub getModDate($) { my($file) = @_; my(@a) = stat($file); if (scalar(@a) <= 0) { return undef; } return $a[9]; } # Example use: use POSIX qw(strftime); sub main() { $md = getModDate('/etc/passwd'); $md_str = strftime("%a %b %e %H:%M:%S %Y", localtime($md)); print "md=$md md_str=$md_str\n"; } main();

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.