Getting names of directories under given path
perl
Solution
Use the`-d` file check operator:
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
my $path = $ARGV[0];
die "Please specify which directory to search"
unless -d $path;
opendir( my $DIR, $path );
while ( my $entry = readdir $DIR ) {
next unless -d $path . '/' . $entry;
next if $entry eq '.' or $entry eq '..';
print "Found directory $entry\n";
}
closedir $DIR;
Problem
I am trying to get the names of all first level directories under given path. I tried to use File::Find but had problems. Can someone help me with that?