为了在Windows中列出pathes,我写了下面的Perl函数(在StrawBerry运行时环境下执行).
sub listpath
{
my $path = shift;
my @list = glob "$path/*";
#my @list = <$path/*>;
my @pathes = grep { -d and $_ ne "." and $_ ne ".." } @list;
}
Run Code Online (Sandbox Code Playgroud)
但它无法正确解析包含空间的目录,例如:
当我发出以下代码时:listpath("e:/ test/test1/test11/test111/test1111/test11111 - Copy");
该函数返回一个包含两个元素的数组:
1:e:/ test/test1/test11/test111/test1111/test11111 2: -
我想知道glob是否可以解析空间目录.非常感谢.
小智 19
尝试bsd_glob
改为:
use File::Glob ':glob';
my @list = bsd_glob "$path/*";
Run Code Online (Sandbox Code Playgroud)