Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to Get the Last Subdirectories

by admiral_grinder (Pilgrim)
on Mar 12, 2010 at 20:01 UTC ( #828351=note: print w/ replies, xml ) Need Help??


in reply to How to Get the Last Subdirectories

What the hell, here is my stab at this. It doesn't work when it comes across a unreadable object such as 'C:\System Volume Information', but that might be a issue in the Path::Class::Dir than my code.

#!perl use strict; use warnings; use Path::Class; #file(), dir() use Cwd; #getcwd() my $start_dir = dir( $ARGV[0] || getcwd() ); #print "DEBUG: Scanning $start_dir\n"; $start_dir->recurse( callback => \&report_leaf_dirs ); sub report_leaf_dirs { my $object = shift; #print "DEBUG: processing $object\n"; return unless $object->is_dir(); # Test to see if we can read it unless( $object->open() ) { warn "Unable to open $object\n"; return; } # Test for sub directories foreach my $child ( $object->children() ) { return if $child->is_dir(); } print "$object\n"; }


Comment on Re: How to Get the Last Subdirectories
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-09-23 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls