程序因文件名中的元音变音而死亡 [英] Program dies on umlauts in filename

查看:23
本文介绍了程序因文件名中的元音变音而死亡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望你能帮帮我,我找不到我的代码停止的原因.我会很感激每一次改进,我必须使用 Perl,我以前从未这样做过!此外,我必须在 Windows 文件系统上工作.

I hope you can help me, I can't find the reason why my code stops. I'd be grateful for every enhancement, I have to work with Perl and I've never done it before! Also I have to work on a Windows File System.

错误:

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

Could not open file '' No such file or directory at C:\Users\schacherl\Documents\perl\tester.pl line 29, line 1.

仅供参考:FILElog.txt 文件包含子文件夹,如

FYI: the FILElog.txt file contains subfolders like

vps_bayern_justiz_15027148042584275712825768716427"

"vps_bayern_justiz_15027148042584275712825768716427"

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

EDALOG contains the fully qualified link to the EDA-File

"W:\EGVP\manuelleNachrichten\heruntergeladene_DONE\EGVP_GP114503661816195610088017045919978\attachments\Staßfurt_AIA100.eda"

"W:\EGVP\manuelle Nachrichten\heruntergeladene_DONE\EGVP_GP114503661816195610088017045919978\attachments\Staßfurt_AIA100.eda"

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

At this exact file above the program dies. For all others it seems to work so far, just those "Staßfurt" files it can't handle as it seems. If I'm encoding the other files with UTF-8 like the first one, I get a lot of

UTF-8 "\x84" 不映射到 Unicode 在C:\Users\zhengphor\Documents\perl\tester.pl 第 32 行,第 4 行.

UTF-8 "\x84" does not map to Unicode at C:\Users\zhengphor\Documents\perl\tester.pl line 32, line 4.

UTF-8 "\x81" 不映射到 Unicode 在C:\Users\zhengpor\Documents\perl\tester.pl 第 32 行,第 4 行.

UTF-8 "\x81" does not map to Unicode at C:\Users\zhengpor\Documents\perl\tester.pl line 32, line 4.

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

If I don't have a Staßfurt file, it works fine. This is just the Part where the error happens, I've excluded the whole handling of the $returner variable.

我真的很感激!我不知道为什么 Staßfurt 文件会出现这个错误.

I'd be really grateful! I can't find why the Staßfurt file makes this error.

#!/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;

推荐答案

在 Windows 上,您需要:

On Windows, you need to either:

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

例如:

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) 的引用而不是变量本身.

Note the use of a reference to the file handle variable (\$fh) instead of the variable itself.

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

As a bonus, using Win32::LongPath allows you to manipulate files with extra long full names (full path beyond the usual limit of 260 characters including the terminating NUL character). (You shouldn't get into a habit of doing this, however, since many other applications can't access such files.)

这篇关于程序因文件名中的元音变音而死亡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆