[BUG?] UTF8 ruby and win32 dir

Hi,

not sure at all about this one, but on my windows XP pro French,

doing a Dir.entries.each on a folder with accented letter doesn’t gives
UTF-8 back but rather the local encoding for my filesystem :

in a folder containing the sub-folders:
têté
âfül

this script:
file = File.open(“ouput.txt”,“w”).binmode
Dir.new(“d:/test_accent”).each{ |dir|
file.puts dir
}

spits out a latin1 file (windows-1252, i guess) and not a unicode one
when run using ruby -KU.

I would have expected ruby to give back UTF8 values when using the
standard library.

Should I convert the latin1 to UTF-8 by myself ?
Thanks a lot,

···


Pierre Baillet
Ruby: happy 1.8.0!

Hi,

not sure at all about this one, but on my windows XP pro French,

doing a Dir.entries.each on a folder with accented letter doesn’t gives
UTF-8 back but rather the local encoding for my filesystem :

in a folder containing the sub-folders:
t�êt�é
�âf�ül

this script:
file = File.open(“ouput.txt”,“w”).binmode
Dir.new(“d:/test_accent”).each{ |dir|
file.puts dir
}

spits out a latin1 file (windows-1252, i guess) and not a unicode one
when run using ruby -KU.

Ruby does not convert encodings implicitly, even when you specify -Ku.
-Ku means “treating data as in UTF-8”, not “converting incoming data
into UTF-8”.

So if underlying OS (Windows XP, this case) gives Ruby file names in
Latin-1, or any other encoding, Ruby passes them to you directly.
Blame Microsoft for not giving file names in your favorite encoding,
and convert them to UTF-8 by yourself.

						matz.
···

In message “[BUG?] UTF8 ruby and win32 dir” on 03/08/05, Pierre Baillet oct@zoy.org writes:

Hello again again,

Hi,

Ruby does not convert encodings implicitly, even when you specify -Ku.
-Ku means “treating data as in UTF-8”, not “converting incoming data
into UTF-8”.

So if underlying OS (Windows XP, this case) gives Ruby file names in
Latin-1, or any other encoding, Ruby passes them to you directly.
Blame Microsoft for not giving file names in your favorite encoding,
and convert them to UTF-8 by yourself.

That’s what I was afraid to heard. This os definitely sucks sometimes :slight_smile:
Thanks for your quick answer, Matz.

Now that you have finished with ruby1, i suppose you are busy with Rite.
I wish you all the success you deserve !

  					matz.

Pierre.

···

On Tue, Aug 05, 2003, Yukihiro Matsumoto wrote:

Pierre Baillet
En essayant continuellement on finit par réussir. Donc : plus ça rate,
plus on a de chances que ça marche.
Devise Shadok