Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading a directory

2 views
Skip to first unread message

Jason Vriends

unread,
Nov 12, 2003, 7:34:58 PM11/12/03
to
Can someone help me out. I'm trying to have perl read a directoy into an
array with the date of the file. I tried to use "LS" then have perl use
Regular Experssions but there must be an easier way


Jürgen Exner

unread,
Nov 12, 2003, 7:39:27 PM11/12/03
to

perldoc -f readdir
perldoc -f stat

jue


Gunnar Hjalmarsson

unread,
Nov 12, 2003, 8:00:20 PM11/12/03
to

perldoc -f stat

Example (using also a hash):

my $dir = '/path/to/some/directory';

opendir DIR, $dir or die $!;
my @files = grep -f "$dir/$_", readdir DIR;
closedir DIR or die $!;

my %moddates = ();
$moddates{$_} = localtime( (stat "$dir/$_")[9] ) for @files;

print "$_ : $moddates{$_}\n" for keys %moddates;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Tintin

unread,
Nov 13, 2003, 1:17:38 AM11/13/03
to

"Jason Vriends" <vri...@rogers.com> wrote in message
news:SkAsb.7436$iD1....@news04.bloor.is.net.cable.rogers.com...

> Can someone help me out. I'm trying to have perl read a directoy into an
> array with the date of the file. I tried to use "LS" then have perl use
> Regular Experssions but there must be an easier way

Please read http://www.cs.tut.fi/~jkorpela/usenet/xpost.html before you
decide to go off multi-posting again.


0 new messages