tristan ball wrote:
>
> Mike Reilley wrote:
> >
> > HI ALL,
> >
> > I have a file like
> > www.txt
> > There may be multiple copies of the file in the same directory
> > www.txt
> > www1.txt
> > www5.txt
> > I need to pick out the latest file by date and time drop the numeric
> > suffix and copy the file to another directory.
> > There is no relationship between the numeric suffix and the date &
> > time. In the above it might be that www1.txt is the latest.
> > I would appreciate any direction that the PERL EXPERTS would care
> > To discuss.
> > TIA
Your technique is not something to pass on IMHO.
A couple of changes may be appropriate or necessary:
use strict;
> opendir LD,".\";
opendir LD, '.' or die "Error on opendir: $!\n"; #
> @files = readdir LD;
my @files = readdir LD;
> closedir LD;
>
> $y = 0;
my $y = 0;
my $new_file = '';
> foreach $f (@files) {
foreach my $f (@files) {
next if $f !~ /^www\d+\.txt$/; # drop non-conforming files
> ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
> = stat($f);
my $mtime = (stat $f)[9]; # much simpler
> if($mtime > $y && -f $f) {
> $new_file = $f;
> $y = $mtime
> }
> }
> print("$new_file\n");
Now you can copy it to the new dir.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles http://www.wgn.net/~dbe/
/ ) /--< o // // Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_ http://www.freeyellow.com/members/dbecoll/
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]