Re: List of directories within a directory
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Wed, 30 Jan 2008 02:30:16 GMT
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:
opendir(DIR, $dirname) or die "can't open $dirname: $!";
while (defined($file = readdir(DIR))) {
next if($file =~ m/^\./);
next if($file eq "");
"" is not a valid file name so this test will *always* fail.
$ mkdir ''
mkdir: cannot create directory `': No such file or directory
$ touch ''
touch: cannot touch `': No such file or directory
push (@filenames, $file);
Since you didn't test the file type your @filenames array contains all types including subdirectories.
}
closedir(DIR);
but how do I do it for the directories within a directory
my @dir_names = grep -d "$dirname/$_", readdir DIR;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- Follow-Ups:
- Re: List of directories within a directory
- From: Al Moodie
- Re: List of directories within a directory
- References:
- List of directories within a directory
- From: Al Moodie
- List of directories within a directory
- Prev by Date: Re: List of directories within a directory
- Next by Date: Re: "negative" regexp
- Previous by thread: Re: List of directories within a directory
- Next by thread: Re: List of directories within a directory
- Index(es):