#!/usr/bin/perl
use strict;
use File::Copy::Recursive qw(dircopy dirmove);
use Time::Piece;
my $MDY = localtime->mdy('');
print "$MDY \n\n";
my $src = 'e:/pervasive/staging/summit/';
my $dest = 'e:/pervasive/test/';
my @f = qw(01 02 03 04 05 06 07 08 30
40 41 42 43 44 44 50 80 85 99 );
my %compHash;
for my $n (@f[0]){ # replace with @f if it works for first
$compHash{'C'.$n} = 'APEX'.$n.'2015/C'.$n;
$compHash{'C'.$n.'-2015'} = 'APEX'.$n.'2015/CSW';
};
foreach my $key (sort keys %compHash) {
my $from = $src.$key;
my $to = $dest.$compHash{$key};
print "Moving $from $to\n";
dirmove ( $from,$to ) or die "$!";
}
poj | [reply] [d/l] |
I used the hash from this, ultimately. It worked perfectly. I try to stay away from hardcoding stuff as much as I can, but in this situation it was absolutely merited. The way you did this was perfect for me, and I so greatly appreciate your help with this.
| [reply] |
How would I check to see if the file exists with this? So we have @f defined as the list of company numbers (C## - which represents company ID ) and for each of those, we're renaming the directory and moving it, but it breaks when it hits the key that does not exist in the folder (company 6 is not inside my zip, but it is a possible company that CAN be in the zip) so I'm looking for a quick way to check if the actual file, that corresponds with the key in our @f, even exists because if it doesn't, i need to skip it.
I think this will involve next, or exists, or maybe both.
Any insight?
| [reply] |
foreach my $key (sort keys %compHash) {
my $from = $src.$key;
next unless (-e $from);
.
.
poj
| [reply] [d/l] |
if ( -f $file ) { .... } ## $file is a file
elsif ( -d $file ) { ... } ## also could use '_' for speed
else { ,,, } ## Not what we're looking for
Also you may wish to look at 'glob' for getting information about directory contents ( files and/or directories ).
Good Luck...Ed
"Well done is better than well said." - Benjamin Franklin
| [reply] [d/l] |