Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Recursive Directory print

by Laurent_R (Canon)
on Mar 06, 2014 at 18:44 UTC ( [id://1077270]=note: print w/replies, xml ) Need Help??


in reply to Recursive Directory print

If you want to do the recursive search yourself, using the glob function (rather than opendir and readdir) makes it somewhat simpler because glob returns the relative path of the file together with the file. The following program prints only the files, but searches the directories and subdirectories:
use strict; use warnings; search_dir (shift); sub search_dir { my $path = shift; my @dir_entries = glob("$path/*"); foreach my $entry (@dir_entries) { print $entry, "\n" if -f $entry; search_dir($entry) if -d $entry; } }
If you want to print also the directories, you might change the relevant lines to this:
print "$entry is a file \n" if -f $entry; print "$entry is a dir \n" and search_dir($entry) if -d $entry +;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1077270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-18 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found