in reply to Re: Dir Tree in Perl
in thread Dir Tree in Perl
#!/usr/bin/perl ($dir) = @ARGV; open (MYFILE, '>>data.txt') || die; &loopDir($dir, ""); exit; sub loopDir { $dir = "." unless $dir; local($dir, $margin) = @_; chdir($dir) || die "Cannot chdir to $dir\n"; local(*DIR); opendir(DIR, "."); while ($f=readdir(DIR)) { next if ($f eq "." || $f eq ".."); print MYFILE "$margin$f\n"; if (-d $f) { &loopDir($f,$margin." "); } } closedir(DIR); chdir(".."); } close (MYFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Dir Tree in Perl
by afoken (Chancellor) on Nov 04, 2012 at 21:16 UTC |