I am writing a script in perl strawberry. The first thing to do is take the path argument and get a list of directories for that path, and it should be able to distinguish between files and folders. I read several guides on this issue and wrote a script below, but it only works when I give it the path that the script is currently in. If I give it any other way, the -f and -d tests do not work.
EDIT: Clarification: script Paste all the files and folders into @thefiles, if I give him a path different from his 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 is a screenshot: http://i.stack.imgur.com/RMmFz.jpg
Hope someone can help and thanks very much for your time. :)
Aaron source share