in reply to Unix - Keep the last modified file in the directory and move/copy the rest of the files.

Something like the following might get you started. Please understand that it was quickly written and barely tested. I urge you to understand it before using it...

#!/usr/bin/perl -w use strict; use File::Copy; die "Usage: $0 dir destdir\n" unless @ARGV == 2; my ($dir,$mvto) = @ARGV; opendir DIR, $dir or die "Can't open director $dir: $!\n"; # The ST probably isn't necessary... my @files = map { $_->[1] } # map back. sort { $a->[0] <=> $b->[0] } # sort on mtime map { [ -M $_, $_ ] } # store mtime grep { !/\.\.?$/ } # skip . and .. readdir(DIR); closedir DIR; # The latest is in $files[0]. Move the rest. for ( @files[ 1 .. $#files ] ) { copy "$dir/$_", $mvto; # move "$dir/$_", $mvto; # Don't use move unless you're sure this w +orks. }
-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Unix - Keep the last modified file in the directory and move/copy the rest of the files.
  • Download Code