I
inthepickle
Apparently I am making a stupid mistake, but I can't see it. I have a
text file with one 6 digit number per line which corresponds to a file
name on a network directory. I want to find each file, then copy it
somewhere. I am trying to do it in steps to make the find a little
faster. If it finds the file in the first step, it should not go
through to the others, but it does. Testing a file, I found it in the
fist step. The length of $f was 38. Can't figure out why it is not
picking up on the length of $f in the second step. What am I doing
wrong? Please help!
use File::Find ;
system ( "cls" ) ;
$incoming = "D:/Cutlist.txt" ; #directory to look in for job sheets:
$destination = "D:/SWFiles/"; #copy destination
open INC, $incoming ; #open file
@cutlist = <INC> ; #assign file to array
close INC ; #close file
foreach ( @cutlist ) { #for every number in file
$swfile = $_ ;
chop ( $swfile ) ;
$subdir = substr ( $swfile,0,4 ) ; #get first 4 digits
print "Searching Y:/SolidWorks Files/$subdir\n" ;
@filetree = ( "Y:/SolidWorks Files/$subdir" ) ; #set to part sub dir
find ( \&findswfile,@filetree ) ;
if ( length ( $f ) < 2 ) { # if subdir finds failed
print "Searching Y:/SolidWorks Files/\n" ;
@filetree = ( "Y:/SolidWorks Files/" ) ; #set to sw dir
find ( \&findswfile,@filetree ) ;
} ; #end if for sw dir
if ( length ( $f ) < 2 ) {# if subdir & swdir finds failed
print "Searching Y:/\n" ;
@filetree = ( "Y:/" ) ; #set entire drive
find ( \&findswfile,@filetree ) ;
} ; #end if for entire drive
}; #foreach
print "\nEnd Program\n" ;
sub findswfile {
if ( ( /$swfile/ ) & ( /.SLDPRT/ | /.sldprt/ ) ) { #if part and
(caliptal or lower) match
$f = $File::Find::name ; #directory and file name
print " Found: $f\n\n" ;
system ( "copy \"$f\" \"$destination\" >nul" ) ; #copy file to
destination
} else {
return ; #try again
} ; #end file match
} ; #endsub
text file with one 6 digit number per line which corresponds to a file
name on a network directory. I want to find each file, then copy it
somewhere. I am trying to do it in steps to make the find a little
faster. If it finds the file in the first step, it should not go
through to the others, but it does. Testing a file, I found it in the
fist step. The length of $f was 38. Can't figure out why it is not
picking up on the length of $f in the second step. What am I doing
wrong? Please help!
use File::Find ;
system ( "cls" ) ;
$incoming = "D:/Cutlist.txt" ; #directory to look in for job sheets:
$destination = "D:/SWFiles/"; #copy destination
open INC, $incoming ; #open file
@cutlist = <INC> ; #assign file to array
close INC ; #close file
foreach ( @cutlist ) { #for every number in file
$swfile = $_ ;
chop ( $swfile ) ;
$subdir = substr ( $swfile,0,4 ) ; #get first 4 digits
print "Searching Y:/SolidWorks Files/$subdir\n" ;
@filetree = ( "Y:/SolidWorks Files/$subdir" ) ; #set to part sub dir
find ( \&findswfile,@filetree ) ;
if ( length ( $f ) < 2 ) { # if subdir finds failed
print "Searching Y:/SolidWorks Files/\n" ;
@filetree = ( "Y:/SolidWorks Files/" ) ; #set to sw dir
find ( \&findswfile,@filetree ) ;
} ; #end if for sw dir
if ( length ( $f ) < 2 ) {# if subdir & swdir finds failed
print "Searching Y:/\n" ;
@filetree = ( "Y:/" ) ; #set entire drive
find ( \&findswfile,@filetree ) ;
} ; #end if for entire drive
}; #foreach
print "\nEnd Program\n" ;
sub findswfile {
if ( ( /$swfile/ ) & ( /.SLDPRT/ | /.sldprt/ ) ) { #if part and
(caliptal or lower) match
$f = $File::Find::name ; #directory and file name
print " Found: $f\n\n" ;
system ( "copy \"$f\" \"$destination\" >nul" ) ; #copy file to
destination
} else {
return ; #try again
} ; #end file match
} ; #endsub