my $dir = "/home/gaurav/Documents";
opendir my $dh, $dir or die "Couldn't open $dir: $!";
while (readdir $dh) {
next if $_ eq "." or $_ eq ".." ;
print $_, " " x (30 - length($_));
my $file = "$dir/$_";
# ...do file tests against $file here
}
Or use chdir to change the working directory before entering the loop where you do the file tests:
my $dir = "/home/gaurav/Documents";
opendir my $dh, $dir or die "Couldn't open $dir: $!";
chdir($dir);
while (readdir $dh) {
next if $_ eq "." or $_ eq ".." ;
print $_, " " x (30 - length($_));
# ...do file tests against $_ here
}
|