Lamont85 has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
The following script is meant to iterate through all files within a directory, including subdirectories. It seemed the solution would be easy. Unfortunately, this spits out something about an invalid dirhandle at line 18 (marked with ***).
#!C:\Perl64\bin\perl.exe use strict; use warnings; my $remoteaddr = "//192.168.25.2/"; my %directories = ( media => $remoteaddr . "Media", software => $remoteaddr . "Software" ); sub getdir { my $dir = shift; opendir (my $dh, $dir) || die qq(Cannot opendir: $dir); while( my $file = readdir($dh)) { #********************************* +***** next if ($file =~ m[^\.{1,2}$]); # Ignore . and .. my $path = $dir .'/'. $file; if (-e $path) { # do some stuff } elsif (-d $path) { getdir($path); } closedir ($dh); } } foreach my $directory (keys %directories) { getdir($directories{$directory}); }
Any help would be appreciated.
-cory-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bad file descriptor error
by jethro (Monsignor) on Mar 22, 2010 at 10:06 UTC | |
by cdarke (Prior) on Mar 22, 2010 at 10:59 UTC | |
by jethro (Monsignor) on Mar 22, 2010 at 11:51 UTC | |
by Lamont85 (Novice) on Mar 22, 2010 at 20:57 UTC | |
|
Re: Bad file descriptor error
by thillai_selvan (Initiate) on Mar 22, 2010 at 10:01 UTC |