我正在为其文件名包含> = 255个字符的文件创建目录。我尝试创建文件时出现问题。我在Windows上,所以MAX_PATH是260个字符。我已经看到你可以使用前缀'\\?\'(Source)来扩展最大路径。我只是不确定如何使用它来创建Windows中具有长名称的文件。我在创建它时尝试在目录前面附加前缀以及文件,但到目前为止我尝试的内容似乎没有用。
use strict;
use warnings;
use Win32::Unicode::File;
use Cwd;
my $fh = Win32::Unicode::File->new;
my $prefix = "\\\\?\\";
#current directory
my $currDir = &cwd;
#puts the prefix in front of the current directory
chdir($prefix.$currDir."/testFolder")or die "Unable to enter dir $!\n";
#the long name string plus the prefix appended before it
my $longName="$prefix";
#longName iterator
my $j=1;
#while length of the long file name is <=255,
#concatenate that with the current j and then
#iterate j
while(length($longName.$j)<=255){
$longName = $longName.$j;
$j++;
}
#print $longName,"\n";
#file iterator
my $i=1;
#Makes files with no extensions.
#Concatenates the file iterator to the long file name
#so that we can have 5 different files.
while($i<=5){
$fh->open('>', "$longName$i") or die "Length of specified path too long \n\t$!\n";
close($fh);
$i++;
}
此外,当我运行此特定版本的代码时,我收到此错误。
Undefined subroutine &Errno::ERROR_FILE_EXISTS called at C:/Perl64/site/lib/Win32/Unicode/Error.pm line 31.