List of directories with a directory

A

Al Moodie

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.
 
J

Jürgen Exner

Al Moodie said:
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
 
J

Joe Smith

Al said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,828
Messages
2,569,736
Members
45,518
Latest member
vlonesshirt

Latest Threads

Top