Pregunta

I am using File::Find::Rule on Strawberry Perl Windows.

when I run the following code:

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

I get the list of files in this format:

C:\data\mydata\file/1.xls 

and not this format:

C:\data\mydata\file\1.xls

What could be the problem?

¿Fue útil?

Solución

The only problem is your expectations. C:\data\mydata\file/1.xls is a perfectly valid Windows path.

File::Spec can normalize the path for you.

use File::Spec::Functions qw( canonpath );
$path = canonpath($path);

or

use File::Spec::Functions qw( canonpath );
@files = map { canonpath($_) } @files;

Otros consejos

The cause is probably manual concatenation of the dir and the filename. You can fix it using File::Spec:

use File::Spec;

my @files = File::Find::Rule->file()->in( $dir );
foreach my $file (@files){
    say File::Spec->catfile($file);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top