[wxruby-users] Incompatible encoding from drag and drop?
Christian Schmidt
lists at ruby-forum.com
Sat Mar 7 05:18:55 EST 2009
Hi Alex,
thanks a lot! It works like a charm.
Have a nice weekend,
Christian.
Alex Fenton wrote:
> Christian Schmidt wrote:
>> it really works on your box?
>>
>
> Yes, the reason being that in OS X, file names are encoded in UTF-8, and
> this is the encoding of the string file name that wxRuby returns.
>> Ok, on my system, when I use the example file, it throws:
>>
>> "No such file or directory - C:\ööäèé.txt"
>>
>> I'm working on XP-Home, SP3. German locales
>> ruby -v: ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
>
> On Windows, file names aren't encoded in UTF-8, but in a local encoding
> (for me, and probably you, CP1252). So the filename returned by wxRuby
> doesn't exist.
>
> I think we should fix this so that wxRuby methods that accept or return
> file paths return those strings in an encoding that can be passed
> straight to Ruby's File/Dir methods.
>
> In the meantime, you can work around this by manually converting the
> filepaths to the correct encoding before opening them:
>
> require 'iconv' # at the top of your script
>
> files.each do | file |
> if Wx::PLATFORM == 'WXMSW'
> file = Iconv.conv('CP1252', 'UTF-8', file)
> end
> .... process file as normal
> end
>
> alex
--
Posted via http://www.ruby-forum.com/.
More information about the wxruby-users
mailing list