Steve Golamco wrote:
> I have a directory (say, dir-A) wherein every 10 minutes an 'autosave' file
> is created.  These files are named 'reports.*.autosave' where the asterisk
> would represent some numeric value.  These numeric values are NOT in
> any particular sequence.  Every 10 minutes, I need to copy the most recent
> (latest) of these save file to another directory (say, dir-B) .  I cannot
> make the application directly generate the autosave file to dir-B.  Is
> there
> a way to do this in Perl?

First you have to find some way to determine the creation date of the file.
If you are doing this on a *nix system then there is no creation date so you
have to use another method.  If you are on a system that has a creation date
then there may be a module somewhere that gives you that information.

An example of what you need using the modification time that works on *nix
systems:

my $dir = 'dir-A';

opendir my $dh, $dir or die "Cannot open '$dir' $!";

my ( $last_file, $last_modified );

while ( my $file = readdir $dh ) {
    ( $last_file, $last_modified ) = ( $file, -M "$dir/$file" )
        if $last_modified < -M "$dir/$file";
    }

print "The newest file in $dir is $last_file.\n";




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to