[MacOS X]Dir#.glob over accentuated named directories ???

U

Une Bévue

over MacOS X the user could have named directories using accentuated
characters like :

"Défaut" (for Default)

when doing a Dir.glob over the parent directory of it i get :

De'faut

is there a way to get the "right" name in UTF-8 ??? instead of ASCII ?

because, after getting those directories i memorize this directory name
to a label "Défaut" and move the directory to a www safe string "defaut"
(no accentuate characters).
 
7

7stud --

Une Bév
ue said:
over MacOS X the user could have named directories using accentuated
characters like :

"D�faut" (for Default)

when doing a Dir.glob over the parent directory of it i get :
is there a way to get the "right" name in UTF-8 ??? instead of ASCII ?

Ruby has the "right" name--it's just that your display device is unable
to display it. For instance, when I use Dir.glob to read a directory
that contains a file named cafe.txt, where the 'e' has an accent, this
is the output:

/TestData/cafe_\_314_\_201.txt #underscores added by me

which is the UFT-8 character :

_\_x_cc_\_x_81 #underscores added by me

in octal format. You can prove that to yourself by doing this:

puts "cafe_\_xcc_\_x81" #remove the underscores

When you say I get:

that is completely meaningless. That is your display device's
interpretation of the string. As for what display device you are using
and what encodings it can display, e.g. ascii, UTF-8, or even what
character your filename actually contains, who knows? The forum
software and/or my browser are interpreting your problematic character
as a black square with a question mark inside it.
 
U

Une Bévue

7stud -- said:
That is your display device's
interpretation of the string.

fine, thanks ;-)

in fact this is due to my text editor (TextMate); i did the following
experiment :

make a folder on desktop with an accentuated character e run the script
:

puts "Defaut" # here the e is accentuated as the folder on desktop

Dir.glob( "/Users/yt/Desktop/*" ).each { | f | puts f }

on "RubyMate" (the TextMate "console") i get the right think but copying
from "RubyMate" to a ruby utf-8 encoded file (still within TextMate) i
get e' (e ans the accent apart)...
 
7

7stud --

Une Bév
ue said:
fine, thanks ;-)

in fact this is due to my text editor (TextMate); i did the following
experiment :

make a folder on desktop with an accentuated character e run the script
:

puts "Defaut" # here the e is accentuated as the folder on desktop

Dir.glob( "/Users/yt/Desktop/*" ).each { | f | puts f }

on "RubyMate" (the TextMate "console") i get the right think but copying
from "RubyMate" to a ruby utf-8 encoded file (still within TextMate) i
get e' (e ans the accent apart)...

What is a 'ruby utf-8 encoded file'?

As an aside, how do you like TextMate? You might try running your
program in Terminal to see if things make more sense.
 
U

Une Bévue

7stud -- said:
What is a 'ruby utf-8 encoded file'?

nothing more than an utf-8 encoded text file...
As an aside, how do you like TextMate? You might try running your
program in Terminal to see if things make more sense.

from Terminal i get :

De##faut ( using ls -al )

running the script from terminal gave me :

Defaut with the right accent for the line "puts "Defaut""

and "/Users/yt/Desktop/De'faut"

the accent apart on the terminal window but pasting it in TextEdit, the
right think...

the reason i was confused abou that ?
 
7

7stud --

Une Bév
ue said:
nothing more than an utf-8 encoded text file...


from Terminal i get :

De##faut ( using ls -al )

-ls- is most likely an ancient program written in C, and it doesn't know
how to read or output UTF-8 characters. However, if you run your ruby
program in terminal, Terminal is capable of displaying a UTF-8 character
if given a UTF-8 character. It doesn't matter whether the UTf-8
character is part of a string that is a single work or whether the UTF-8
character is part of a string that is a path.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top