How do I create then use long Windows paths from Perl?

前端 未结 5 1457
南笙
南笙 2020-12-05 15:01

I have part of a build process that creates a hideously long paths in Windows. It\'s not my fault. It\'s several directories deep, and none of the directory names are abnorm

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 15:05

    This should really be a comment but posting code in comments is hardly useful.

    UNC paths do not work either:

    C:\> net share
    perlbuild    e:\home\src
    
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use File::Path qw(make_path);
    use File::Slurp;
    use Path::Class;
    
    my $top = dir('//Computer/perlbuild');
    my @comps = ('0123456789') x 30;
    
    my $path = dir($top, @comps);
    
    make_path $path, { verbose => 1 };
    
    my $file = file($path, 'test.txt');
    
    write_file "$file" => 'This is a test';
    
    print read_file "$file";
    

    Result:

    mkdir \\Computer\perlbuild\0123456789\0123456789\0123456789\0123456789\0123456
    789\0123456789\0123456789\0123456789\0123456789\0123456789\0123456789\0123456789
    \0123456789\0123456789\0123456789\0123456789\0123456789\0123456789\0123456789\01
    23456789\0123456789: No such file or directory; The filename or extension is too
     long at C:\Temp\k.pl line 15
    

提交回复
热议问题