1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #!/usr/bin/perl -w
- # usage: copyscandirs <TargetDir> <ScanDirPattern>
- # note that you must not be in <TargetDir> but in the directory in which the
- # scna dirs are, which should be moved!
- #
- # algorithm:
- # get list of scan dirs
- # parse scan dir names (base name + number)
- # check largest number in goal dir
- # move and rename the scandirs
- use Getopt::Std;
- getopts('uhn');
- $TargetDir = "exexrangedurscan" ;
- $BaseFileName = "scan" ;
- if ($opt_u) {
- print "usage: copyscandirs <TargetDir> <ScanDirPattern>\n";
-
- }
- print "**************************\n";
- print "copyscandirs\n";
- $NumCmdArgs = $#ARGV+1 ;
- print "Number of command line arguments: $NumCmdArgs \n" ;
- if ($#ARGV >= 0)
- {
- $TmpTargetDir = $ARGV[0];
- # check existence of target dir: http://www.pageresource.com/cgirec/ptut17.htm
- if (-e $TmpTargetDir) {
- $TargetDir = $TmpTargetDir ;
- } else {
- print "TargetDir $TmpTargetDir doesn't exist \n" ;
- print " --> using default $TargetDir \n";
- }
- }
- if ($#ARGV >=1)
- {
- $BaseFileName = $ARGV[1] ;
- }
- print "TargetDir = $TargetDir \n";
- my(@DirNames) = glob "$BaseFileName*" ;
- my(@TargetScanDirs) = glob "$TargetDir/$BaseFileName*" ;
- $MaxTargetNumber = 0;
- foreach $Dir (@TargetScanDirs)
- {
- # print "$Dir\n" ;
- $_ = $Dir ;
- $Pattern = "$TargetDir/$BaseFileName";
- /$Pattern(.*)/ ;
- if ($1 > $MaxTargetNumber) {
- $MaxTargetNumber = $1 ;
- }
- }
- print "MaxTargetNumber = $MaxTargetNumber \n";
- $NextTargetNumber = $MaxTargetNumber + 1;
- foreach $Dir (@DirNames)
- {
- print "move $Dir to $TargetDir/$BaseFileName$NextTargetNumber\n" ;
- system ("mv $Dir $TargetDir/$BaseFileName$NextTargetNumber") ;
- ++$NextTargetNumber ;
- }
|