in reply to Re^2: selcting all files in a given directory except......
in thread selcting all files in a given directory except......
save the script as myls.pl, and run the script like this#!/usr/bin/perl use strict; use warnings; my $dir = $ARGV[0] || $ENV{HOME}; my @files; if (-d $dir){ opendir (my $DIR, $dir); @files = grep {/^(?!\.{1,2}\z)/} readdir($DIR); closedir($DIR); } else { die("can't open the dir, $dir\n"); } foreach my $file (@files) { print "$file\n"; }
ps. the $ENV{HOME} exist in the windows environment??$ perl myls.pl /home
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |