Here's an example that will take all the files from the directories specified and move them to a new directory:
#!/usr/bin/perl -w
use File::Copy;
@dirs_of_interest = ('/home/user/data1',
'/home/user/data2',
'/home/user/data3');
$new_location = '/home/user/data4';
foreach $dir (@dirs_of_interest) {
opendir DIRH, $dir or die "Couldn't open $dir: $!\n";
foreach $file (sort readdir DIRH) {
move("$dir/$file","$new_location/$file");
}
closedir DIRH;
}
If you need to "walk" the file tree to find the directories on your list, that can be done with some more code. Also, if you need to move only select files, look into the Perl function "glob" for identifying filenames using shell shorthand (i.e., '*.txt' or 'ag*.pl').
roswell1329
Junior Poster in Training
71 posts since May 2006
Reputation Points: 21
Solved Threads: 2