non-English path problem

I’ve been stumped on this problem for days and I have a feeling that it
is really simple…

I am trying to create a folder at the following location:
C:\documents and settings[username]\application data\amaranth

The following code works great unless the username has a non-English
character in it (for example, Joé). In this case, when I try to use the
path, I get a “path not found” error, and it says that the path is:
C:\documents and settings\Jo\application data\amaranth

From what I can see, my code is striping out any non-English characters.
I’m not quite sure how to get these non-English characters to show up.

Here is my code:


SHGetFolderPath =
Win32API.new(“shell32.dll”,“SHGetFolderPathW”,[“P”,“I”,“P”,“I”,“P”],“I”)

path = " " * 256

SHGetFolderPath.call(0,0x001A,0,0,path)

$appPath = path.strip.gsub("\000","") + “\amaranth”


Does anyone have any idea what I’m doing wrong? I’m pretty new at this
so if you can be as non-technical as possible, I would appreciate it.

:slight_smile:

Amanda

Okay, I changed my code, but I’m still having the same problem. Here is
my new code:

path = " " * 256
path = ENV[‘APPDATA’].rstrip
$appPath = path + “\MyGame”

Hi,
----- Original Message -----
From: “Amanda Fae” [email protected]
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” [email protected]
Sent: Saturday, November 10, 2007 5:27 PM
Subject: non-English path problem

path = " " * 256
:slight_smile:

Amanda

You should convert widechar string to multibyte string with
WideCharToMultiByte API.
Try this code:

SHGetFolderPath =
Win32API.new(“shell32.dll”,“SHGetFolderPathW”,[“P”,“I”,“P”,“I”,“P”],“I”)

WideCharToMultiByte =
Win32API.new(‘kernel32’, ‘WideCharToMultiByte’, ‘ILPIPIPP’, ‘I’)
path = “\0” * 256

buf=“\0”*256
SHGetFolderPath.call(0,0x001A,0,0,path)
WideCharToMultiByte.call(0,0,path,-1,buf,256,0,0)
$appPath = buf.strip + “\amaranth”

Regards,
Park H.

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\José> # non english user name

===
require “Win32API”
SHGetFolderPathW = Win32API.new(“shell32”, “SHGetFolderPathW”,
“LIILP”, “L”)
buffer = 0.chr * 256 * 2 # its wide
SHGetFolderPathW.call(0,0x001A,0,0,buffer)
=> “C\000:\000\\000D\000o\000c\000u\000m\000e\000n\000t\000s\000 \000a
\000n\000
d\000 \000S\000e\000t\000t\000i\000n\000g\000s\000\\000J\000o\000s
\000\351\000
\000A\000p\000p\000l\000i\000c\000a\000t\000i\000o\000n\000 \000D\000a
\000t\000
a\000\000\000\000 … \000”

require “windows/unicode”
include Windows::Unicode
path = wide_to_multi(buffer.dup)
=> “C:\Documents and Settings\Jos\351\Application Data
\000\000\000\000\000\00
0\000\000\000 … \000”

path.strip ## => “C:\Documents and Settings\Jos\351\Application
Data”
===end===

Easier way…

==begin==
require “win32/dir”
Dir.constants # => [“ADMINTOOLS”, “COMMON_MUSIC”, “DRIVES”,
“NETWORK”, “STARTUP”, “COMMON_APPDATA”, “CONTROLS”, “HISTORY”,
“MYMUSIC”, “PROGRAMS”, “BITBUCKET”, “COMMON_STARTMENU”, “INTERNET”,
“PRINTHOOD”, “WINDOWS”, “COMMON_FAVORITES”, “DESKTOPDIRECTORY”,
“NETHOOD”, “STARTMENU”, “COMMON_ALTSTARTUP”, “COMMON_VIDEO”,
“MYDOCUMENTS”, “PROGRAM_FILES_COMMON”, “APPDATA”, “COMMON_PROGRAMS”,
“FONTS”, “PRINTERS”, “TEMPLATES”, “COMMON_DOCUMENTS”, “DESKTOP”,
“MYVIDEO”, “SENDTO”, “COMMON_ADMINTOOLS”, “COMMON_TEMPLATES”,
“LOCAL_APPDATA”, “PROGRAM_FILES”, “ALTSTARTUP”, “COMMON_PICTURES”,
“FAVORITES”, “PERSONAL”, “SYSTEM”, “COMMON_DESKTOPDIRECTORY”,
“COOKIES”, “MYPICTURES”, “RECENT”, “CDBURN_AREA”, “COMMON_STARTUP”,
“INTERNET_CACHE”, “PROFILE”]

Dir::APPDATA # => “C:\Documents and Settings\Jos\351\Application
Data”
==end==