Perl move files script
Here is a little script I wrote that you can use to move a list of files. Supply it a list of file names. In this case the file names I was supplied didn’t have .pdf on them, so I had to concatentate that onto the file names. I’ve covered this earlier with respect to file::copy and ditto, but this is an out of the box solution that you can use. Just change your path variables. Make sure the volumes are mounted that you are using. Remove the concatenation on line 17 if you don’t need it or change it to what you need.
#!/usr/bin/perl
use File::Copy;my $movefile;
my @dirfile, @movelist;open (MOVELIST, ‘/Users/bradrice/bin/keypdflist.txt’);
my $srcpath = ‘/Volumes/Users/Admin/Sites/clientfiles/pdf/’;
my $movepath = ‘/Volumes/10.1.5.235/pdfs/’;while () {
chomp $_;
push (@movelist, $_);
}
foreach $movefile(@movelist){
$movefile .= “.pdf”;
print “$srcpath$movefile”.” — “. “$movepath$movefile”.”\n”;
copy(”$srcpath$movefile”, “$movepath$movefile”);
}
December 30th, 2005 at 2:29 am
#! /bin/sh
ext=.pdf
movefile=/Users/bradrice/bin/keypdflist.txt
srcpath = /Volumes/Users/Admin/Sites/clientfiles/pdf/
movepath = /Volumes/10.1.5.235/pdfs/
for i in `cat $movefile`
do
cp $srcpath/$i $movepath/$i$ext
echo “$srcpath/$i -> $movepath/$i$ext”
done
May 28th, 2006 at 9:15 am
Came across your script while searching how to move a file. However, you don’t seem to be moving them at all. You copy them.
And, BTW, I don’t see the point of the @movelist array. Why not something like:
#!/usr/bin/perl
use File::Copy;
my $movefile;
my @dirfile;
my $srcpath = ‘/Volumes/Users/Admin/Sites/clientfiles/pdf/’;
my $movepath = ‘/Volumes/10.1.5.235/pdfs/’;
open (MOVELIST, ‘/Users/bradrice/bin/keypdflist.txt’);
while (<MOVELIST>) {
chomp $_;
$new = $_ . “.pdf” unless /\.pdf$/i;
print “$srcpath$movefileâ€.†— “. “$movepath$newâ€.â€\nâ€;
copy(â€$srcpath$movefileâ€, “$newâ€);
}
(But that is still a copy, not a move)
May 28th, 2006 at 5:45 pm
That take it down a level. I use an array, because often times I need the array for additional processing, but you are right, that would work. If you want to move the file just replace copy with move. Both subs come in with the File::Copy package. I usually find myself both making a copy and a move in the same routine.