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

  2. Al Moodie

    Al Moodie Guest

    I have the answer from another source.

    Al Moodie.
     
    Al Moodie, Jan 30, 2008
    #2
    1. Advertisements

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

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

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 (here). After that, you can post your question and our members will help you out.