Milleniumlegend
IS-IT--Management
- Dec 16, 2003
- 135
foreach my $f (@files){
next if ($name eq ".");
next if ($name eq "..");
if (-d $f) {
if (($f eq "bin")) {
$loc = "$pwd\/bin";
#print "Entering bin and Folder = $f and Path = $loc\n";
&addFiletoHash($f,$loc);
}
if (($f eq "int")) {
$loc = "$pwd\/int";
#print "Entering int and Folder = $f and Path = $loc\n";
&addFiletoHash($f,$loc);
}
}
}
}
# Add files to the hash and also the location.
sub addFiletoHash($f,$loc){
my $folder = shift;
my $path = $loc;
print "Folder is $folder and location is $loc\n";
chdir($f) or die "Unable to enter $folder:$!`\n";
&readfile($folder,$path);
}
Adding this line causes grief chdir($f) or die "Unable to enter $path:$!`\n";
Could someone please tell me if there is anything wrong with the code. I am trying to search for files and check them if they are folders if the folder name is bin then change the directory to bin and read the file names and store the location. I have maintained an hash to store the filename as the key and location as the value. I would like to enter the filename to the Hash and also the location. But there is something that has gone wrong in the above code. Could some one please help.
Many thanks
next if ($name eq ".");
next if ($name eq "..");
if (-d $f) {
if (($f eq "bin")) {
$loc = "$pwd\/bin";
#print "Entering bin and Folder = $f and Path = $loc\n";
&addFiletoHash($f,$loc);
}
if (($f eq "int")) {
$loc = "$pwd\/int";
#print "Entering int and Folder = $f and Path = $loc\n";
&addFiletoHash($f,$loc);
}
}
}
}
# Add files to the hash and also the location.
sub addFiletoHash($f,$loc){
my $folder = shift;
my $path = $loc;
print "Folder is $folder and location is $loc\n";
chdir($f) or die "Unable to enter $folder:$!`\n";
&readfile($folder,$path);
}
Adding this line causes grief chdir($f) or die "Unable to enter $path:$!`\n";
Could someone please tell me if there is anything wrong with the code. I am trying to search for files and check them if they are folders if the folder name is bin then change the directory to bin and read the file names and store the location. I have maintained an hash to store the filename as the key and location as the value. I would like to enter the filename to the Hash and also the location. But there is something that has gone wrong in the above code. Could some one please help.
Many thanks