For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2005 > Getting Date Stamp of a file on a Win32 System









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Getting Date Stamp of a file on a Win32 System
Dave Adams

2005-07-28, 9:59 pm

On a Win32 system, how do you get a date stamp of a file?

I used:=20

#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use File::stat;
my $filename =3D "test.txt";
my $stat =3D stat($filename);
print Dumper($stat);
my $modified_time =3D stat($filename)->mtime;
print ("The modified time of $filename is: $modified_time");

But this only gets me time. Nothing in the element list for STAT
seems to give me the date.

Any suggestions?
Thanks in advance.
DA
Robert

2005-07-28, 9:59 pm

I found this maybe it will help:


use strict;
use File::stat;
use POSIX qw(strftime);


my $file = 'test.txt';


my $s = stat($file) || die "Can't stat($file) $!\n";


my $modtime = strftime('%Y-%m-%d', localtime($s->mtime));


print "Modification time of $file is $modtime\n";


Dave Adams

2005-07-29, 5:01 pm

Robert,

Thanks very much. It works great. Your code was nice and simple.

Much appreciated.
DA

On 7/28/05, Robert <catcher@linuxmail.org> wrote:
> I found this maybe it will help:
>=20
>=20
> use strict;
> use File::stat;
> use POSIX qw(strftime);
>=20
>=20
> my $file =3D 'test.txt';
>=20
>=20
> my $s =3D stat($file) || die "Can't stat($file) $!\n";
>=20
>=20
> my $modtime =3D strftime('%Y-%m-%d', localtime($s->mtime));
>=20
>=20
> print "Modification time of $file is $modtime\n";
>=20
>=20
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20
>=20
>

Robert

2005-07-29, 5:01 pm

"Dave Adams" <davidlamontadams@gmail.com> wrote in message
news:3c3c86440507290741264155fe@mail.gmail.com...
>Robert,
>
>Thanks very much. It works great. Your code was nice and simple.
>
>Much appreciated.
>DA


I can't take credit. I just GOOGLE'd it.

Glad it helped.

Robert


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com