A
Adam Petrie
Hi guys/gals,
I'm pretty new to Perl, so please keep that in mind.
It looks like File::Find goes through all the subdirectories of the
current directory, which isn't what I want. I just want all the
contents of the current directory.
On doing some research, many people have recommended doing something
like the following:
-----------
$home_dir = ''; #changed to protect the innocent
opendir(DIR,$home_dir) or die "Can't open the current directory:
$home_dir $!\n";
# read file/directory names in that directory into @names
@names = readdir(DIR) or die "Unable to read current dir:$!\n";
closedir(DIR);
foreach $name (@names) {
next if ($name eq "."); # skip the current directory entry
next if ($name eq ".."); # skip the parent directory entry
if (-d $name){ # is this a directory?
print "found a directory: $name<br />";
}
else {
print "found a file: $name <br />";
}
}
-----------
However, the -d doesn't seem to be working right. Most of the output
comes from the else part when it should be showing many directories
instead.
What is going on? Any other solutions?
I'm pretty new to Perl, so please keep that in mind.
It looks like File::Find goes through all the subdirectories of the
current directory, which isn't what I want. I just want all the
contents of the current directory.
On doing some research, many people have recommended doing something
like the following:
-----------
$home_dir = ''; #changed to protect the innocent
opendir(DIR,$home_dir) or die "Can't open the current directory:
$home_dir $!\n";
# read file/directory names in that directory into @names
@names = readdir(DIR) or die "Unable to read current dir:$!\n";
closedir(DIR);
foreach $name (@names) {
next if ($name eq "."); # skip the current directory entry
next if ($name eq ".."); # skip the parent directory entry
if (-d $name){ # is this a directory?
print "found a directory: $name<br />";
}
else {
print "found a file: $name <br />";
}
}
-----------
However, the -d doesn't seem to be working right. Most of the output
comes from the else part when it should be showing many directories
instead.
What is going on? Any other solutions?