thinkhy thinkhy - 1 year ago 90
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.

Answer Source

Try bsd_glob instead:

use File::Glob ':glob';
my @list = bsd_glob "$path/*";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download