How do I create a Unicode directory on Windows using Perl?

前端 未结 2 523
面向向阳花
面向向阳花 2020-12-18 06:28

I struggle to create directory names containing Unicode. I am on Windows XP and Perl Camelbox 5.10.0.

Up until now I used to use File::Path qw ( make_pa

2条回答
  •  独厮守ぢ
    2020-12-18 07:21

    Just updating this question for 2018.

    Unbelievably, ActivePerl 5.24 still does not support simply passing Unicode paths to open()/mkdir(), and by extension File::Path::mkpath(), because the underlying Perl code still calls the 20th-century ASCII version of Windows CreateFile(). Insanity! How could this not have been a higher priority than the myriad obscure Perl changes made in the intervening 10 years?!

    This is true even if you 'use utf8;' or a myriad other incantations.

    So, even today, we still have to have special-case code for Windows for this most basic function (creating/accessing Unicode filenames).

    Fortunately, the Win32::Unicode module has a nice, easy-to-use Win32::Unicode::Dir::mkpathW() function which does exactly what you want and works for Unicode (as well as great copyW() and moveW() functions).

    Unfortunately, this module hasn't passed its installation tests since Perl 5.16 and ActiveState dropped it from its handy ppm repository ( https://code.activestate.com/ppm/Win32-Unicode/ ).

    Fortunately, there is a way to get it working, as the 3 tests that fail (relating to "print") are not used for file/directory creation:

    Step 1: ppm install dmake

    Step 2: ppm install MinGW

    Step 3: perl -MCPAN -e shell then force install Win32::Unicode

    Step 1 and 2 are required even if you already have Microsoft Visual Studio installed on your computer; apparently Perl is now built with MinGW and modules must be as well.

    Phew.

提交回复
热议问题