in reply to Need help with creating a filename only array
Your mistake was, that you prepended to filename and afterwards your regex wouldn't match anymore. Here's a fix:
my @files = (); my $dir = $rootPath . $input->param('path'); $dir .= '/' unless $dir =~ m#/$#; opendir (DIR, $dir) or die $!; @files = grep { -f } map { "$dir$_" } grep { !m#^\.# } readdir (DIR); closedir (DIR);
That's the working version of your code. But all hidden files (on *n?x, that is) are removed, too. If you want them to, all you have to do is remove that regex. "." and ".." will get filtered out as well since they are directories, too. At least on my box it worked all fine. That one line should then look like this:
@files = grep { -f } map { "$dir$_" } readdir (DIR);
Regards,
-octo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Need help with creating a filename only array
by S_Shrum (Pilgrim) on Jul 27, 2002 at 07:15 UTC | |
by flocto (Pilgrim) on Jul 27, 2002 at 07:20 UTC | |
by S_Shrum (Pilgrim) on Jul 27, 2002 at 08:44 UTC |