Connecting Tech Pros Worldwide Help | Site Map

List of directories with a directory

  #1  
Old January 30th, 2008, 12:55 AM
Al Moodie
Guest
 
Posts: 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.
  #2  
Old January 30th, 2008, 02:45 AM
Al Moodie
Guest
 
Posts: n/a

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.
  #3  
Old January 30th, 2008, 04:35 AM
Jürgen Exner
Guest
 
Posts: n/a

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
  #4  
Old February 5th, 2008, 08:55 AM
Joe Smith
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive zipping of Directories in Windows Jandre answers 5 February 6th, 2007 10:25 PM
Creating and Getting list of websites/Virtual Directories Lucky answers 2 August 17th, 2006 01:05 PM
Creating and Getting list of websites/Virtual Directories lucky answers 2 August 17th, 2006 01:05 PM
How to Clear the List of Oracle Client Homes install on a User Machine... John answers 3 July 19th, 2005 11:05 PM