MkIIISupra
Programmer
Code:
#!/bin/bash/perl -w
# This is a rename and move script. The goal is to rename files then move them to their
# appropriate folders, and then e-mail (hopefully) the files to pre-defined people.
use warnings;
use strict;
use diagnostics;
use Time::Local;
use File::Copy;
my $date = `date`; # Load $date with system date.
chomp $date; # Clear any trailing spaces
my $mMonth = substr ($date, 4, 3); # Move month into mMonth to be used to perform renames and moves.
# This If statement converts mMonth to the Fiscal month
# Jan = 07 / Feb = 08...
if ($mMonth eq "Jan")
{
$mMonth = "07";
}
elsif ($mMonth eq "Feb")
{
$mMonth = "08";
}
elsif ($mMonth eq "Mar")
{
$mMonth = "09";
}
elsif ($mMonth eq "Apr")
{
$mMonth = "10";
}
elsif ($mMonth eq "May")
{
$mMonth = "11";
}
elsif ($mMonth eq "Jun")
{
$mMonth = "12";
}
elsif ($mMonth eq "Jul")
{
$mMonth = "01";
}
elsif ($mMonth eq "Aug")
{
$mMonth = "02";
}
elsif ($mMonth eq "Sep")
{
$mMonth = "03";
}
elsif ($mMonth eq "Oct")
{
$mMonth = "04";
}
elsif ($mMonth eq "Nov")
{
$mMonth = "05";
}
elsif ($mMonth eq "Dec")
{
$mMonth = "06";
}
else
{
print "Oh HELP ME! The date function failed! \n";
}
my $source = "";
my $destination = "";
opendir DH,"/UCSC/WinXP_C/Documents and Settings/mcdonaldj.FACILITIES/Local Settings/Temp" or die "Couldn't open /UCSC/WinXP_C/Documents and Settings/mcdonaldj.FACILITIES/Local Settings/Temp : $!";
while($_ = readdir(DH)){
if ($_ eq "1a-fac housing reads.xls"){
$source = "/UCSC/WinXP_C/Documents and Settings/mcdonaldj.FACILITIES/Local Settings/Temp/1a-fac housing reads.xls";
$destination = "/UCSC/MONTHLY DROP/$mMonth-fac housing reads.xls";
open IN, $source or die "Can't get the file $source, did you run it? : $!\n";
open OUT, "> $destination" or die "Can't write to $destination: $!\n";
while(<IN>){
print OUT $_;
}
}
elsif ($_ eq "1b-fac housing usages.xls"){
$source = "/UCSC/WinXP_C/Documents and Settings/mcdonaldj.FACILITIES/Local Settings/Temp/1b-fac housing usages.xls";
$destination = "/UCSC/MONTHLY DROP/$mMonth-fac housing reads.xls";
open IN, $source or die "Can't get the file $source, did you run it? : $!\n";
open OUT, "> $destination" or die "Can't write to $destination: $!\n";
while(<IN>){
print OUT $_;
}
}
}
Okay I got this to copy the first file and rename it in the process. But the second file doesn't get touched. I thought the while statement would reload and retest each file instance but it doesn't appear that way... or I am doing it incorrectly. What am I missing?
One by one the penguins return my sanity, as day by day Microsoft steals my sanity!
OpenSuSE 10.0 kicks fanny!