Connecting Tech Pros Worldwide Help | Site Map

List of directories with a directory

Al Moodie
Guest
 
Posts: n/a
#1: Jan 30 '08
I have a directory with 200 sub directories in it. How do I create a
list of the sub directory names?

I know how create a list of all the files in a directory:

opendir(DIR, $dirname) or die "can't open $dirname: $!";
while (defined($file = readdir(DIR))) {
next if($file =~ m/^\./);
next if($file eq "");
push (@filenames, $file);
}
closedir(DIR);

but how do I do it for the directories within a directory

Al Moodie.
Al Moodie
Guest
 
Posts: n/a
#2: Jan 30 '08

re: List of directories with a directory


On Tue, 29 Jan 2008 19:45:50 -0500, Al Moodie <nospam@nospam.com>
wrote:
Quote:
>I have a directory with 200 sub directories in it. How do I create a
>list of the sub directory names?
I have the answer from another source.

Al Moodie.
Jürgen Exner
Guest
 
Posts: n/a
#3: Jan 30 '08

re: List of directories with a directory


Al Moodie <nospam@nospam.comwrote:
Quote:
>I have a directory with 200 sub directories in it. How do I create a
>list of the sub directory names?
>
>I know how create a list of all the files in a directory:
>but how do I do it for the directories within a directory
I would simply use File::Find and prune the search tree ata depth of 2.

jue
Joe Smith
Guest
 
Posts: n/a
#4: Feb 5 '08

re: List of directories with a directory


Al Moodie wrote:
Quote:
On Tue, 29 Jan 2008 19:45:50 -0500, Al Moodie <nospam@nospam.com>
wrote:
>
Quote:
>I have a directory with 200 sub directories in it. How do I create a
>list of the sub directory names?
>
I have the answer from another source.
Was it anything like this:

perl -MFile::Find -e 'find(sub {push @files,$File::Find::name if -f $_},@ARGV); \
print join "\n","Found:",@files,"";' /etc/rc.d
Closed Thread