How do I check if a Unicode directory exists on Windows in Perl? -
I have to check whether a Unicode directory exists in Perl or not. I am using Windows XP and Perl Camelbox 5.10.0.
If I try to create a directory (such as Sinn has suggested here), which is already present, the program ends.
Unfortunately if (! -d $ dir_name) {# directory build $ dir_name}
does not recognize the Unicode directory or I'm doing something completely stupid, I checked it Before trying to encode the name of the directory, but the result is the same.
How do I check for the existence of a Unicode directory?
While answering your first question, I forgot that it provides a decent interface I I will go and answer However, for your immediate problem, what you need to do is do not automatically die
when the CreateDirectory
call fails, but to check if the error code is 0xb7
( ERROR_ALREADY_EXISTS
), then you go on your way to your delightful path. The problem is that it is difficult to go on your happiness.
Win32 :: GetANSIPath
using the Perl function (just keep an eye on the full length of the path): #! Use / usr / bin / perl strict; Use warnings; Use utf8; Use Encoded QW (encode); Use the file: Slurp; File :: spec :: functions use qw (catfile); Win32; Use Win32 :: API; Continuous ERROR_ALREADY_EXISTS = & gt; Use 0xb7; My $ dir_name = 'Wilgorad'; Unless (Win32 :: CreateDirectory ($ dir_name)) {my $ err = $ ^ E; If ($ err == ERROR_ALREADY_EXISTS) {Warning "directory exists, there is no problem \ n"; } And {die Win32 :: FormatMessage ($ ^ E); }} My $ ansi_path = Win32 :: GetANSIPathName ($ dir_name); Warning "$ ansi_path \ n";
Oh, and, good luck to delete that directory.
In a serious vein, however, the entire Windows Unicode file operation is a bit of a mess of things. / P>
As far as I understand these things, if you want to work with the path of the Unicode character to use the pell function like open
, then you have to type the ANSI path Example:
My $ file = catfile ($ dir_name, 'test.txt'); Open my $ FH, '& gt;', $ file or die '' can not create $ file: $! ";
will fail
My $ file = catfile ($ ansi_path, 'test.txt'); Open my $ FH; 'gt; ; '$ File or die' 'can not create $ file: $! ";
will be successful (at least on my system) if you are going to use Win32 API functions to deal only with files (and your case may be easy) You do not need the ANSI path. There is a bunch of modules to assist you in later times.
Comments
Post a Comment