469,325 Members | 1,637 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

List of directories with a directory

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.
Jan 30 '08 #1
3 3536
On Tue, 29 Jan 2008 19:45:50 -0500, Al Moodie <no****@nospam.com>
wrote:
>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.
Jan 30 '08 #2
Al Moodie <no****@nospam.comwrote:
>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
Jan 30 '08 #3
Al Moodie wrote:
On Tue, 29 Jan 2008 19:45:50 -0500, Al Moodie <no****@nospam.com>
wrote:
>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
Feb 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by david | last post: by
14 posts views Thread by kpp9c | last post: by
4 posts views Thread by thoseion | last post: by
3 posts views Thread by rn5a | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.