Hi, I'm writing a script in perl strawberry. The first thing it needs to be able to do is take a path argument and get a directory listing for that path, and it needs to be able to distinguish between files and folders. I read some tutorials on the subject and wrote the script below, but it only works when I give it the path that the script is currently residing in. If I give it any other path, the -f and -d tests don't work.
EDIT: Clarification: The script DOES put all the files and folders into @thefiles if I give it a path other than it's own, it's just the -f and -d tests that don't work.
use Getopt::Long;
my $dir;
GetOptions('-d=s' => \$dir);
opendir(DIR, $dir) or die "BORKED";
@thefiles = readdir(DIR);
print DIR;
closedir(DIR);
@filez;
@dirz;
foreach $file (@thefiles){
if (-f$file){
push(@filez, $file);
}
if (-d$file){
push(@dirz, $file);
}
}
print "files: @filez \n";
print "Directories: @dirz \n";
Here's a screenshot: http://i.imgur.com/RMmFz.jpg
Hope someone can help and thanks very much for your time. :)