By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,253 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,253 IT Pros & Developers. It's quick & easy.

List of directories with a directory

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.