aussiegeek
aussiegeek

Reputation: 2950

File.open with ruby on windows with a unicode filename

I have a script running on Ruby 1.9.1 on Windows 7

I've distilled my script down to

File.open("翻譯測試.txt")

and still can't get it to work. I know there are issues with Ruby 1.9 filename handling on windows (Using the Windows ANSI library), but would be happy enough with a work around that is callable from Ruby

Upvotes: 5

Views: 1390

Answers (2)

Jet Abe
Jet Abe

Reputation: 420

This should help you string = "翻譯測試" # by default, string is encoded as "ASCII" string.force_encoding("SHIFT-JIS") # retags the String as SHIFT-JIS or whatever UTF char set that #is in

Heres a nice read a bit about char encoings in 1.9.1

http://yehudakatz.com/2010/05/17/encodings-unabridged/

Upvotes: 0

Luis Lavena
Luis Lavena

Reputation: 10378

Most of the Unicode changes like file and directory operations have been improved in 1.9.2 (trunk) and other bigger changes will be merged pretty soon.

As bobince pointed out, this was already asked:

Unicode filenames on Windows in Ruby

Upvotes: 1

Related Questions