List of directories with a directory

Discussion in 'Perl' started by Al Moodie, Jan 30, 2008.

  1. Al Moodie

    Al Moodie Guest

    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, Jan 30, 2008
    #1
    1. Advertising

  2. Al Moodie

    Al Moodie Guest

    On Tue, 29 Jan 2008 19:45:50 -0500, Al Moodie <>
    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.
     
    Al Moodie, Jan 30, 2008
    #2
    1. Advertising

  3. Al Moodie <> wrote:
    >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ürgen Exner, Jan 30, 2008
    #3
  4. Al Moodie

    Joe Smith Guest

    Al Moodie wrote:
    > On Tue, 29 Jan 2008 19:45:50 -0500, Al Moodie <>
    > 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
     
    Joe Smith, Feb 5, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Finkel
    Replies:
    0
    Views:
    505
    Joel Finkel
    Sep 12, 2003
  2. Jeffry van de Vuurst
    Replies:
    2
    Views:
    547
    Jeffry van de Vuurst
    Jul 30, 2003
  3. =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=

    Multiple bin-directories with virtual directories?

    =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=, Nov 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    839
    =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=
    Nov 9, 2004
  4. Paul F
    Replies:
    4
    Views:
    645
    Mark Fitzpatrick
    Jun 25, 2008
  5. Adam Petrie
    Replies:
    8
    Views:
    330
    Adam Petrie
    Oct 11, 2004
Loading...

Share This Page