Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re(3): Find and Print Directory Names

by cjf (Parson)
on Jul 07, 2002 at 17:29 UTC ( #179996=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Find and Print Directory Names
in thread s and replace

First off, Use strict warnings and diagnostics. It'll make debugging a lot easier.

Secondly, try removing the        finddir("$root$file"); from within the foreach loop. You're exiting the loop after the first iteration.

Update: Oops. Read that wrong. Hang on a sec.

Update 2:

my %config = ( home => '/home/cjf/' ); my %user = ( site_id => 'code' ); my @alldir = finddir("$config{home}$user{site_id}"); print $_, "\n" for @alldir; sub finddir { my $root = shift; chomp $root; $root = $root . '/' unless ( $root =~ m|/$| ); local *DIR; opendir DIR, $root or die $!; my @userfiles = sort grep !/^\.\.?\z/, readdir DIR; my @direct; foreach my $file (@userfiles) { next unless ( -d "$root$file" ); my $dir = "$root$file"; $dir =~ s/^\Q$config{home}$user{site_id}\E//; push(@direct, $dir); } return @direct; }

That will return all directories in $config{home}$user{site_id} but not go into the sub directories. Is that what you're looking for?


Comment on Re(3): Find and Print Directory Names
Select or Download Code
Replies are listed 'Best First'.
Re: Re(3): Find and Print Directory Names
by andrew (Acolyte) on Jul 07, 2002 at 17:39 UTC
    no I want to return all the direcotries is $config(home)$user{site_id}
      You really, really should consider File::Find (I see its already been suggested, but I think its worth mentioning out again).
      use File::Find; find (sub { print "$_\n" if -d; }, $dir);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-08-01 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls