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-
In reply to Bad file descriptor error by Lamont85
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |