Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Reading Files Across Directories and Sub Directories

by Anonymous Monk
on Apr 26, 2017 at 13:40 UTC ( [id://1188969]=note: print w/replies, xml ) Need Help??


in reply to Re: Reading Files Across Directories and Sub Directories
in thread Reading Files Across Directories and Sub Directories

This one resulted in all kinds of trouble, like infinite loops :D This works like a charm on the other hand.
sub search_dir { my ($dir) = @_; print "Entered search_dir sub, working with directory => $dir \n"; my $dh; # handle if ( !opendir ($dh, $dir)) { warn "Unable to open $dir: $!\n"; return; } my @FILES = grep { $_ ne '.' && $_ ne '..' } readdir($dh); foreach my $file (@FILES) { my $path = "$dir/$file"; if ( -d $path ) { print "Directory $path found\n"; search_dir ($path); } else { print "File $path found\n"; } } closedir ($dh); } # END of search_dir sub ############## Output: ... File /csvfiles/2015/12/22.csv found Directory /csvfiles/2015/10 found Entered search_dir sub, working with directory => /csvfiles/2015/10 File /csvfiles/2015/10/16.csv found File /csvfiles/2015/10/22.csv found Directory /csvfiles/2015/11 found Entered search_dir sub, working with directory => /csvfiles/2015/11 File /csvfiles/2015/11/16.csv found File /csvfiles/2015/11/11.csv found ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found