File class chokes on Norwegian Characters :(
-
I just discovered that if I have a folder with Norwegian characters (Γ¦ ΓΈ Γ₯ Γ Γ Γ ) Ruby claims it doesn't exist.
If you make a folder *C:\test_æøΓ₯* and then in the console
File.exists?('C:\\test_æøΓ₯\\')
it returnsError: #<Errno::ENOENT: No such file or directory
If you remove the characters and then test - everything works.
Any workarounds? (No, I can't ensure files/folders doesn't have the characters nor rename them. It'd cause havoc to our file at the office.) -
Strange... just after I published 'file_found?(path)' http://forums.sketchucation.com/viewtopic.php?p=168430#p168430
My clunky method will work so long as only the tested file or topmost directory contains the accented characters... If anything down the path has them it fails...
We can't split the path beyond a file/folder and it's container...
file_found?("C:\test_æøΓ₯") true, but...
file_found?("C:\test_æøΓ₯\myfile.txt") error- won't work unless you split it down and test for the file's container "C:\test_æøΓ₯\", but then you can't test for the file within the folder as it fails again...We need a fix for this - it must be possible...
-
The
File.exists?
was only a sample. It also fails the methods that opens up a file.
I came across this when I tried to use Rick's pageExIm plugin. When it tries to save the file it chokes.Fortunately the script isn't scrambled so I can patch it myself if I can find something that works.
The script gets the model path from
Sketchup.active_model.path
and I wonder if this is the culprit where SU returns an UTF-8 String. Or some other encoding...I tried a dirty hack I found on the internet:
fname.unpack("U*").map{|c|c.chr}.join
without any better luck. -
The thing is though... I also get the error when typing in the string in the console. ... does the console go via SU that uses UTF-8 encoding?
-
Don't understand why my hack doesn't work when I add it Rick's script...
This works.
@unknownuser said:
fname = 'C:\test æøΓ₯\'
C:\test æøΓ₯\
File.exists?(fname)
false
fname
C:\test æøΓ₯\
fname.length
15
x=fname.unpack("U*").map{|c|c.chr}.join
C:\test æøΓ₯\
x.length
12
File.exists?(x)
true
-
doh! I made a silly typo. The hack worked.
Though - this hack only works while the characters can be translated to normal ASCII... -
I'd say that model.path returning a UTF-8 string, when Ruby works with ASCII, is a bug. ? or not? Certainly needs a better solution though.
-
I've updated my file_found?(path) code here http://forums.sketchucation.com/viewtopic.php?p=169225#p169225 ...
Advertisement