Code:
#!/usr/bin/perl
# PERL MODULES USED
use DBI;
use DBD::ODBC;
use DBD::File;
use Time::localtime;
use Time::HiRes;
use File::Path;
use File::Copy;
use File::Basename qw( fileparse );
use File::Path qw( make_path );
use File::Spec;
use File::Find;
use FileHandle;
use File::Slurp;
use File::PerlMove;
use Archive::Zip;
print "Modules have been initialized.\n";
# CONFIG HASH
my %compHash =
("e:/pervasive/staging/summit/C01" => "e:/pervasive/test/APEX012015
+/C01",
"e:/pervasive/staging/summit/C02" => "e:/pervasive/test/APEX022015
+/C02",
"e:/pervasive/staging/summit/C03" => "e:/pervasive/test/APEX032015
+/C03",
"e:/pervasive/staging/summit/C04" => "e:/pervasive/test/APEX042015
+/C04",
"e:/pervasive/staging/summit/C05" => "e:/pervasive/test/APEX052015
+/C05",
"e:/pervasive/staging/summit/C06" => "e:/pervasive/test/APEX062015
+/C06",
"e:/pervasive/staging/summit/C07" => "e:/pervasive/test/APEX072015
+/C07",
"e:/pervasive/staging/summit/C08" => "e:/pervasive/test/APEX082015
+/C08",
"e:/pervasive/staging/summit/C30" => "e:/pervasive/test/APEX302015
+/C30",
"e:/pervasive/staging/summit/C40" => "e:/pervasive/test/APEX402015
+/C40",
"e:/pervasive/staging/summit/C41" => "e:/pervasive/test/APEX412015
+/C41",
"e:/pervasive/staging/summit/C42" => "e:/pervasive/test/APEX422015
+/C42",
"e:/pervasive/staging/summit/C43" => "e:/pervasive/test/APEX432015
+/C43",
"e:/pervasive/staging/summit/C44" => "e:/pervasive/test/APEX442015
+/C44",
"e:/pervasive/staging/summit/C50" => "e:/pervasive/test/APEX502015
+/C50",
"e:/pervasive/staging/summit/C80" => "e:/pervasive/test/APEX802015
+/C80",
"e:/pervasive/staging/summit/C85" => "e:/pervasive/test/APEX852015
+/C85",
"e:/pervasive/staging/summit/C99" => "e:/pervasive/test/APEX992015
+/C99",
"e:/pervasive/staging/summit/C01-2015" => "e:/pervasive/test/APEX0
+12015/CSW",
"e:/pervasive/staging/summit/C02-2015" => "e:/pervasive/test/APEX0
+22015/CSW",
"e:/pervasive/staging/summit/C03-2015" => "e:/pervasive/test/APEX0
+32015/CSW",
"e:/pervasive/staging/summit/C04-2015" => "e:/pervasive/test/APEX0
+42015/CSW",
"e:/pervasive/staging/summit/C05-2015" => "e:/pervasive/test/APEX0
+52015/CSW",
"e:/pervasive/staging/summit/C06-2015" => "e:/pervasive/test/APEX0
+62015/CSW",
"e:/pervasive/staging/summit/C07-2015" => "e:/pervasive/test/APEX0
+72015/CSW",
"e:/pervasive/staging/summit/C08-2015" => "e:/pervasive/test/APEX0
+82015/CSW",
"e:/pervasive/staging/summit/C30-2015" => "e:/pervasive/test/APEX3
+02015/CSW",
"e:/pervasive/staging/summit/C40-2015" => "e:/pervasive/test/APEX4
+02015/CSW",
"e:/pervasive/staging/summit/C41-2015" => "e:/pervasive/test/APEX4
+12015/CSW",
"e:/pervasive/staging/summit/C42-2015" => "e:/pervasive/test/APEX4
+22015/CSW",
"e:/pervasive/staging/summit/C43-2015" => "e:/pervasive/test/APEX4
+32015/CSW",
"e:/pervasive/staging/summit/C44-2015" => "e:/pervasive/test/APEX4
+42015/CSW",
"e:/pervasive/staging/summit/C50-2015" => "e:/pervasive/test/APEX5
+02015/CSW",
"e:/pervasive/staging/summit/C80-2015" => "e:/pervasive/test/APEX8
+02015/CSW",
"e:/pervasive/staging/summit/C85-2015" => "e:/pervasive/test/APEX8
+52015/CSW",
"e:/pervasive/staging/summit/C99-2015" => "e:/pervasive/test/APEX9
+92015/CSW"
);
print "Hash assigned! \n\n";
##Variables
my $tm=localtime();
my ($day,$month,$year)=($tm->mday,$tm->mon+1,$tm->year+1900);
my $MDY;
my $dayday = sprintf("%02d",$day % 100);
my $size = length($day);
if($size < 2) {
$MDY = "$month$dayday$year";
}
else {
$MDY = "$month$day$year";
}
print "$MDY \n\n";
print "Variables and Time assigned! \n";
#Foreach C## -> /sql-alt/e/pervasive/APEXCCYYYY/CS## or /sql-alt/e/per
+vasive/APEXCCYYYY/CSW
foreach my $key(keys %compHash) {
my $value = $compHash{$key};
move($key , $value);
print "Successfuly moved $key to $value .\n";
}
Basically, everything passes, and it prints that it has Successfully moved the $key (being the first file path, original location) to the $value (final location, but it's not actually moving the files.
Anyone see anything right off that I am doing wrong? Can I not use file paths in a hash for easy moving purposes?
I tried, in PowerShell: move $key (wrote out the file path) , $value (wrote this path out as well, note both were copied from the hash including the quotes) and it worked succesfully. What am I missing?
I *did* try write_file($key,$value); but this let me to "permission denied"
I feel like I am missing something silly, and that it's likely an easy fix, but after 8-10 hours of wracking my brain I cannot seem to figure it out.
##EDIT
Turns out - it's a permissions issue. If I am trying to move the folder to the destination by hand I am prompted with a window requesting admin access in order to perform the operation. I'd wager that this is the culprit as the script works... well... at least the error checking. Then my manual tests confirmed it's a permissions issue.
Thanks a ton for your alls help on this.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.