我被这段代码卡住了。也许原因是道路上有重音的人物,我不知道。我正在使用的代码如下
my $var2 = realpath('C:\Users\brmelovi\Script\backups');
$source1 = 'N:\NBS_AR\COLLECTION\1.0 Times\2.0 Collections México\1. Macro de solicitação de Desglose';
$name1 = 'macro';
my $absol = path($source1)->absolute;
my @dire = $absol->children( qr/^$name1/);
say $dire[0];
$dire[0]->copy($var2);
return 1;文件和路径都存在。我的代码已经使用了另一条路径和名称,如下所示
my $var2 = realpath('C:\Users\brmelovi\Script\backups');
$source1 = 'N:\NBS_AR\SISTEMAS AR\Macro Credit Analysis & Collection';
$name1 = 'Credit Analysis';
my $absol = path($source1) -> absolute;
my @dire = $absol->children( qr/^$name1/);
say $dire[0];
$dire[0]->copy($var2);
return 1;我的头和use语句
use v5.28;
use strict;
use utf8;
use warnings;
use Cwd 'realpath';
use autodie;
use Path::Tiny;错误信息是
在'N:/NBS_AR/COLLECTION/1.0倍/2.0集合MΘxico/1上的错误opendir。宏deΘτπo de Desglose:在第24行没有这样的文件或目录。
编辑:使用
use Encode::Local;
use Encode;谢谢你的解决办法有点粘。
发布于 2018-08-03 23:48:13
是的,可能是道路上的特殊人物。至少,我可以重现所描述的行为,尝试在opendir()上使用UTF-8编码脚本中的目录1. Macro de solicitação de Desglose。
尝试使用编码::Locale在将字符串传递给opendir()之前正确地编码它。
...
use Encode::Locale;
use Encode;
...
$source1 = encode(locale => 'N:\NBS_AR\COLLECTION\1.0 Times\2.0 Collections México\1. Macro de solicitação de Desglose');
...对我起作用了。
https://stackoverflow.com/questions/51680621
复制相似问题