程序在文件名中的变音符号上死掉

时间:2018-02-01 15:11:45

标签: windows perl utf-8 perl-io

我希望你能帮助我,我找不到我的代码停止的原因。我会感激每一项改进,我必须与Perl合作,而我以前从未做过!此外,我必须在Windows文件系统上工作。

错误:

  

无法打开文件''没有此类文件或目录   C:\ Users \ schacherl \ Documents \ perl \ tester.pl第29行,第1行。

供参考: FILElog.txt文件包含

等子文件夹
  

“vps_bayern_justiz_15027148042584275712825768716427”

EDALOG包含EDA文件的完全限定链接

  

“W:\ EGVP \ MANUELLE   消息报\ heruntergeladene_DONE \ EGVP_GP114503661816195610088017045919978 \附件\Staßfurt_AIA100.eda“

在这个程序上面的确切文件中死了。对于所有其他它似乎工作到目前为止,只是那些“Staßfurt”文件,它似乎无法处理。如果我用UTF-8编码其他文件就像第一个那样,我会得到很多

  

UTF-8“\ x84”未映射到Unicode at   C:\ Users \ zhengphor \ Documents \ perl \ tester.pl第32行,第4行。

     

UTF-8“\ x81”未映射到Unicode at   C:\ Users \ zhengpor \ Documents \ perl \ tester.pl第32行,第4行。

如果我没有Staßfurt文件,它可以正常工作。这只是发生错误的部分,我已经排除了$ returner变量的整个处理。

我真的很感激!我无法找到Staßfurt文件出现此错误的原因。

#!/usr/local/bin/perl -w -l

use Switch;
use Data::Dumper;

`chcp 65001`;
sub getAusgabe{
`dir "W:\\EGVP\\manuelle Nachrichten\\heruntergeladene\\_DONE\\ /AD /B  1>FILElog.txt`;
print 'written file log';
my $filename = 'FILElog.txt';
open(my $fh, '<:encoding(UTF-8)', $filename)
  or die "Could not open file '$filename' $!";

while (my $row = <$fh>) {
chomp $row;
  if($row ne 'DONE'){
    `dir "W:\\EGVP\\manuelle Nachrichten\\heruntergeladene\\_DONE\\$row\\*.eda" /S /B  1>EDAlog.txt`;
    print 'written eda log';
    my $filename = 'EDAlog.txt';
    open(my $fh1, $filename)
      or die "Could not open file '$filename' $!";

      while(my $row2 = <$fh1>){
        chomp $row2;
        print 'Datei:'. $row2;
        open(my $fh2, $row2)
          or die "Could not open file '$$row2' $!";
            print 'ich bin drin';
            while (my $rowFile = <$fh2>) {
                $returner .= $rowFile;
                print 'hier könnte ihr text stehen';
            }

    }
  }

}
print 'ich habe fertig';
return $returner;
}


$ausgabe1 = getAusgabe;

1 个答案:

答案 0 :(得分:0)

在Windows上,您需要:

  • 在使用前手动编码文件名(其中包含非ASCII字符)或
  • 在使用其文件功能时使用为您执行此操作的程序包,例如Win32::LongPath

E.g:

use strict;
use warnings;
use utf8;

use Win32::LongPath;

my $filename;
my $fh;

$filename = "Unicode file with ä in name.txt";
openL(\$fh, '>:encoding(UTF-8)', $filename)
    or die "Could not open file '$filename' ($^E)";
print $fh "Unicode stuff written to file...\n";
close $fh;

$filename = "Another file with ö in it.txt";
# only three-argument version is supported - MODE argument is always required:
openL(\$fh, '<', $filename)
    or die "Could not open file '$filename' ($^E)";
my @lines = <$fh>;
close $fh;

请注意使用对文件句柄变量(\$fh)的引用而不是变量本身。

作为奖励,使用Win32::LongPath允许您操作具有超长全名的文件(超过260个字符的通常限制的完整路径,包括终止NUL字符)。 (但是,您不应养成这样做的习惯,因为许多其他应用程序无法访问此类文件。)

相关问题