Special Characters in ENV[APPDATA] not recognized
-
Hi
I am trying to write some config files for an extension to an users roaming appdata folder but it doesn't work when special characters are used in the user name.
How would you deal with an username containing an ë or é? When for example the Windows Username is 'Tëst' the ENV[APPDATA] will come back with 'Tst'. This results in the inability to write the configuration file.
Thank you for your reply!
Alex
-
On Windows Ruby in the 1.8 trunk cannot handle paths with Unicode characters. This causes many methods in the Ruby
Dir,FileandIOclasses to fail.You will have to use Tig's PCFileTools library along with WIN32OLE class.

-
Note that
ENVinterface may still return unicode characters as escaped numerics:%(#804000)['C:\Users\Półka\AppData\Roaming']
may be returned as:
"C:\\Users\\P\242lka\\AppData\\Roaming"
-
Hopefully when [if] SketchUp gets a 'good' newer version of Ruby this PC limitation will disappear.
If you want to allow for the less esoteric characters like
éthis way returnstrueproperly - no incorrectfalse...s="C:/Users/P**ó**lka/xxx.txt" File.exist? s.unpack("U*").map{|c|begin;c.chr;rescue;c;end}.joinBUT then
C:/Users/Pó**ł**ka/xxxx.txt
still returnsfalsewrongly ! -
You might be able to extract the DOS 8.3 path from EVV['TEMP']. Ruby 1.8 can use DOS 8.3 paths is you have them.
-
The only way around this I found was to write all my own Filepath handling in C++ for LightUp so handling Kanji, etc etc all works correctly.
Advertisement