Is it possible to use perl’s move function from File::Copy module to use a wildcard to move a number of common files with the same file extension?
So far, I can only get move to work if I explicitly name the files.
For example, I wanted to do something like so:
my $old_loc = "/share/cust/abc/*.dat";
my $arc_dir = "/share/archive_dir/";
Right now, I can do one file like so:
use strict;
use warnings;
use File::Copy;
my $old_loc = "/share/cust/abc/Mail_2011-10-17.dat";
my $arc_dir = "/share/archive_dir/Mail_2011-10-17.dat";
my $new_loc = $arc_dir;
#archive
print "Moving files to archive...\n";
move ($old_loc, $new_loc) || die "cound not move $old_loc to $new_loc: $!\n";
What I want to do at the end of my perl program, move all these files named *.dat to an archive directory.
You can use Perl’s
globoperator to get the list of files you need to open:This has the benefit of not relying on a system call, which is unportable, system-dependent, and possibly dangerous.
EDIT: A better way to do this is just to supply the new directory instead of the full new filename. (Sorry for not thinking of this earlier!)