views:

128

answers:

1

I have a piece of code that looks like this:

Dir.new(path).each do |entry|
    puts entry
end

The problem comes when I have a file named こんにちは世界.txt in the directory that I list. On a Windows 7 machine I get the output:

???????.txt

From googling around, properly reading this filename on windows seems to be an impossible task. Any suggestions?

+3  A: 

You're out of luck with pure ruby (either 1.8 or 1.9.1) since it uses the ANSI versions of the Windows API.

It seems like Ruby 1.9.2 will support Unicode filenames on Windows. This bug report has 1.9.2 as target. According to this announcement Ruby 1.9.2 will be released at the end of July 2010.

If you really need it earlier you could try to use FindFirstFileW etc. directly via Win32API.new or win32-api.

gix