#!/usr/bin/perl print "Now moving the files!!!!!!!!!!!!!!!!!!!!\n"; #$FGDCDir="/prodmtdata001/geo/gpms/output/fgdc"; $FGDCDir="/prodmtdata003/geo/shpgen/tigerline/fe_2013"; $TargetDir="/home/m/mccre004/GPMSscripts/FileMoverDir"; print "\$FGDCDir = $FGDCDir\n"; print "after the determing the FGDCDir variable\n"; opendir DHFGDC, $FGDCDir or die "cannot open $FGDCDir: $!"; print " the directory is opened!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; $beginCounter=0; #$beginCounter=5000; #$beginCounter=10000; #$beginCounter=15000; $endCounter=$beginCounter+15000; print "\$endCounter = $endCounter\n"; $TargetFips="72109"; $found="no"; #$counter=$beginCounter; print "pre loop\n"; foreach $dir (readdir DHFGDC){ print "\$dir = $dir\n"; if ($counter >=$beginCounter and $counter<=$endCounter and $dir ne "." and $dir ne ".."){ print "\$beginCounter = $beginCounter\n"; print "\$endCounter = $endCounter\n"; print "$counter: \$dir = $dir\n"; print "----------------------------------------------\n"; $FGDCoutputFile = $FGDCDir . "/" . $dir; print "\$FGDCoutputFile = $FGDCoutputFile"; opendir FGDCFILE, "$FGDCoutputFile"; foreach $file (readdir FGDCFILE){ #print "\$file = $file\n"; $FGDCoutputFileB = $FGDCoutputFile . "/" . $file; #print "\$FGDCoutputFileB = $FGDCoutputFileB\n"; $postSecond=substr($file,8); #print "\$postSecond = $postSecond\n"; $UnderScoreLocation=index($postSecond,"_")+1; $dotLocation=index($postSecond,"."); $Themelength=$dotLocation-$UnderScoreLocation; $Theme=substr($postSecond,$UnderScoreLocation,$Themelength); $fips=substr($postSecond,0,$UnderScoreLocation-1); $statefips=substr($fips,0,2); print "\$Theme = $Theme\n"; print "\$fips = $fips\n"; print "\$statefips = $statefips\n"; $ThemDir = $TargetDir ."/" . $Theme; $ThemDirFile = $ThemDir . "/" . $file; if (-e $ThemDir){ }else{ system "mkdir $ThemDir"; }; if (-e $ThemDirFile){ $AgeThemDirFile = -M $ThemDirFile;#already moved $AgeFGDCoutputFile = -M $FGDCoutputFile;#to be moved if ( $AgeFGDCoutputFile <$AgeThemDirFile){ if ($TargetFips eq $fips){ print "now moving $FGDCoutputFileB\n"; system "cp $FGDCoutputFileB $ThemDir"; $found="yes"; $moveCounter++; }; }; }else{ if ($TargetFips eq $fips){ print "now moving $FGDCoutputFileB\n"; system "cp $FGDCoutputFileB $ThemDir"; $moveCounter++; $found="yes"; }; };#if (-e $ThemDirFile){ };# foreach $file (readdir FGDCFILE){ $counter++; }else{ #print "not reading directory\n"; $counter++; };#if ($counter >=$beginCounter and $counter<=$endCounter and $dir ne "." and $dir ne ".."){ #$counter++; #}else{ #print "not reading directory\n"; #$counter++; };# foreach $dir (readdir DHFGDC){a if ($found eq "yes"){ print "$moveCounter directories under $FGDCDir have been opened and $moveCounter files have been moved to $TargetDir (\$endCounter = $endCounter)\n"; };