# non-English path problem

**URL:** <https://www.ruby-forum.com/t/non-english-path-problem/119770>\
**Category:** Ruby\
**Created:** [November 10, 2007, 9:27am UTC](https://www.ruby-forum.com/t/non-english-path-problem/119770 "2007-11-10T09:27:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amaranth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/47e85d/32.png) [@amaranth](https://www.ruby-forum.com/u/amaranth)\
**Post date:** [November 10, 2007, 9:27am UTC](https://www.ruby-forum.com/t/non-english-path-problem/119770/1 "2007-11-10T09:27:02Z")

</div>

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.

🙂

Amanda

---

<div class="post-metadata">

**Author:** ![amaranth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/47e85d/32.png) [@amaranth](https://www.ruby-forum.com/u/amaranth)\
**Post date:** [November 10, 2007, 10:27am UTC](https://www.ruby-forum.com/t/non-english-path-problem/119770/2 "2007-11-10T10:27:00Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![amaranth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/47e85d/32.png) [@amaranth](https://www.ruby-forum.com/u/amaranth)\
**Post date:** [November 10, 2007, 2:34pm UTC](https://www.ruby-forum.com/t/non-english-path-problem/119770/3 "2007-11-10T14:34:58Z")

</div>

Hi,  
----- Original Message -----  
From: “Amanda Fae” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Newsgroups: comp.lang.ruby  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, November 10, 2007 5:27 PM  
Subject: non-English path problem

> path = " " \* 256  
> 🙂
> 
> ## 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.

---

<div class="post-metadata">

**Author:** ![amaranth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/47e85d/32.png) [@amaranth](https://www.ruby-forum.com/u/amaranth)\
**Post date:** [November 18, 2007, 3:35am UTC](https://www.ruby-forum.com/t/non-english-path-problem/119770/4 "2007-11-18T03:35:38Z")

</div>

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==
