in reply to Recursive Directory Listings
Next, you've fallen prey to the "readdir() returns unqualified names" problem. readdir() is only returning the name of the entries in the directory -- you must prepend the PATH to those names:
Note the line I've commented: I'm combining the directory and the name to make a filename that is meaningful.my $dir = ...; opendir my $dh, $dir or die "can't read $dir: $!"; while (defined(my $name = readdir $dh)) { my $file = "$dir/$name"; # XXX <-- here if (-d $file) { ... } } closedir $dh;
Lastly, your code only goes one level down. To get indefinite depth, you'll need a recursive solution, but you should consider the File::Find module which does this for you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Recursive Directory Listings
by ikegami (Patriarch) on Sep 06, 2005 at 17:18 UTC |