yu.ching.tien
11/18/2007 2:32:00 AM
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==