Skip to content
TD Media Design Technology Communication Design • Technology • Communication
Narrow screen resolution Wide screen resolution Increase font size Decrease font size Default font size
Home arrow Articles arrow Perl script to move partial file list

Perl script to move partial file list

Here is some sample Perl code I hacked together to solve an interesting problem today. We are building an E-commerce web site for a client. This client was given a DVD with over 22,000 product images images equalling over 1 GB of data. However he only wanted to use around 750 of these images. We had a list of file names that he wanted to use and the DVD.

This bit of Perl code looks at the list of images we created with one file name per line and copies these images only to a new directory. Then we simply moved over the images in our new directory to the web server.

#!/usr/bin/perl
use File::Copy;
# establish variable list
my $movefile;
my @movelist;
# this is the path that we copy from
my $srcpath = '/source/path/here';
# this is the path that we copy to
my $movepath = '/destination/path/here/';
my $line;
# this is the file that has the list of files
open (MOVEFILE, '/Path/to/filelist.txt') or die "problem open";
while ( $line = <MOVEFILE> ) {
chomp $line;
push (@movelist, split(/\r/, $line ));
}
foreach $movefile(@movelist){
print "$srcpath$movefile"." — ". "$movepath$movefile"."\n";
system("cp $srcpath$movefile $movepath$movefile");
}

I found these two sample sites that helped in formulating this solution:

http://forums.hostmysite.com/post-6651.html

http://www.bradrice.com/wposx/archives/59

Let us know if you find this code sample helpful.