non-English path problem

A

Amanda Fae

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
 
A

Amanda Fae

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"
 
Y

yu.ching.tien

Microsoft Windows XP [Version 5.1.2600]
(C) 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==
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top