thinkhy thinkhy - 4 months ago 29
Perl Question

Can NOT List directory including space using Perl in Windows Platform

In order to list pathes in Windows,I wrote below Perl function(executed under StrawBerry runtime environment).

sub listpath
my $path = shift;
my @list = glob "$path/*";
#my @list = <$path/*>;
my @pathes = grep { -d and $_ ne "." and $_ ne ".." } @list;

But it can't parse directory including space correctly, for example:

When I issued following code:
listpath("e:/test/test1/test11/test111/test1111/test11111 - Copy");

The function returned an array including two elements:

1: e:/test/test1/test11/test111/test1111/test11111
2: -

I am wondering if glob could parse above space directories. Thanks a lot.


Try bsd_glob instead:

use File::Glob ':glob';
my @list = bsd_glob "$path/*";