File :: Find ::规则和文件分隔符

smi*_*ith 6 perl file-find

File::Find::Rule在Strawberry Perl Windows上使用.

当我运行以下代码时:

@files = File::Find::Rule->file()
                              ->in( $dir );
                              foreach my $file (@files){
                              say $file;
                              }
Run Code Online (Sandbox Code Playgroud)

我得到这种格式的文件列表:

C:\data\mydata\file/1.xls 
Run Code Online (Sandbox Code Playgroud)

而不是这种格式:

C:\data\mydata\file\1.xls
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?

ike*_*ami 6

唯一的问题是你的期望.C:\data\mydata\file/1.xls是一个完全有效的Windows路径.

File :: Spec可以为您规范化路径.

use File::Spec::Functions qw( canonpath );
$path = canonpath($path);
Run Code Online (Sandbox Code Playgroud)

要么

use File::Spec::Functions qw( canonpath );
@files = map { canonpath($_) } @files;
Run Code Online (Sandbox Code Playgroud)