in reply to Finding files , rename then and copy them
The following should get you started:
use strict; use warnings; use File::Copy; my @drives = qw(c: d: e: g: j:); my @dirs = qw(/dir1a/partb/partd /dir2/part1/part2); my @files = qw(OK.txt error.txt unknown.txt); my $bestPath; my $bestTime; for my $drive (@drives) { for my $dir (@dirs) { #Assume first file is sufficient test to find all files #That is, all the files are in the same dir and of the #same age. my $path = "$drive$dir$files[0]"; print "Trying $path\n"; next if ! -e $path; next if defined $bestPath and -M $path < $bestTime; $bestPath = "$drive$dir"; $bestTime = -M $path; } } die "No suitable files found" if ! defined $bestPath; #At this point $bestPath contains the path to the files. #Use rename oldname, newname to rename the files. #The time the program started can be got from $^T. #Use copy("from", "to"); from File::Copy to copy the files.
|
|---|