in reply to List all Dirs, subdirs and files

Check out File::Find. Way easier than rolling your own.

my $dir = "/cdw/home_dir/s006258"; my @dirs; my @files; sub do_stuff { if ( -d $_ ) { push @dirs, $File::Find::name; } else { push @files, $File::Find::name; } } find(\&do_stuff, $dir); foreach my $name (@dirs, @files) { print FILE $name, "\n" if -d $name or -T $name; }

Warning: completely untested.

Update: I had the wrong case on the $File::Find::name variable. Fixed.

Replies are listed 'Best First'.
Re^2: List all Dirs, subdirs and files
by Anonymous Monk on Jul 18, 2005 at 22:24 UTC
    So will this work if I want everything not just a specific file?

      I'm not sure what you're seeing that makes it look like this only gets a specific file? I mean that in an honest manner - there is something in my untested code that made you ask this question, and I'd like to know what it is. On one hand, it could be the key to helping you understand, on the other hand, it could be a blatant error in my untested code.

        Well my text file is blank. Im running it on the unix server so it doesnt have any modules. Is this a module I will have to download or would it come with the perl package that comes with the Unix OS? Thanks again...