Translate My Documents
-
I think this is becoming too complex...
Just make a temporary cmd file in Ruby, then 'openURL' it to read the Registry entry and then write it into a temporary file, that you then read using Ruby to find the path to the current user's 'Documents' folder ? -
On the person's computer, ENV["USERPROFILE"] returns:
"C:\Users\Jim"
When the location is:
What is Equipo? Is it "My Computer"?
(I will now re-read the thread and see what I missed.)
-
Just FYI, there is a User Shell Folder key because, from the article (2003)..
@unknownuser said:
the "Shell Folders" key exists solely to permit four programs written in 1994 to continue running on the RTM version of Windows 95.
The gist of the article is do not rely on registry keys directly and use the system library to read the location of the special folder names. The article is aimed at Windows application developers, but it applies here because reading these registry keys isn't giving the desired result.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
Which in my case looks like this:
But from my previous post, it would not return the desired path either. The real directory name is Usuarios, and not Users.
(My Google skillz rulez!)
-
Jim, did you do a full install in spanish? OR just change the language to spanish on your existing system?
-
Neither, it's not my computer.
Right now, I think the answer is in using Win32API, but need to learn to use it make the system call.
The Dir::PERSONAL would probably work, but there are more than a few dependencies, and it complains about the Ruby Version being 1.8.0 (in SketchUp) instead of my installed 1.8.6, so I can't get it to work easily.
Update: I think I found a single-file (or 2-file) solution. Test pending...
-
@tig said:
... or if it's always on a PC then hack the registry use 'cmd' etc:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders String value: Personal
which will return the path to the 'My Documents' folder in any locale...YES, what TIG said!
Because I "think" XP and earlier used "My Documents",
and Vista (v6) and later (Win 7) uses "Documents" (more like UNIX, Linux and OSX.)
I'm not sure when the change occurs for Windows Server versions.(a) You can call Reg.exe either thru a back-quoted string or IO.popen
(b) Use the standard Ruby library for Windows Registry
ENV['RUBYLIB'+'/lib/win32/registry.rb']
which relies upon Win32API.sodef get_docs_dir @dir='' if RUBY_PLATFORM.include?('mswin') reglib = ENV['RUBYLIB']+'/lib/win32/registry.rb' if test( ?e, reglib ) require reglib # require uses absolute paths before iterating $; key = 'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' Win32;;Registry;;HKEY_CURRENT_USER.open( key ) do |reg| @dir = reg['Personal'] end # let block end normally so key gets automatically closed end else raise( NotImplementedError, 'Not a Windows Platform' ) end return @dir end # def
EDIT: changed string append to concat in line 4
-
require 'win32dir.rb' true p Dir::DESKTOP "C:\\Users\\Thomas\\Desktop" nil p Dir::PERSONAL "C:\\Users\\Thomas\\Documents" nil p Dir::APPDATA "C:\\Users\\Thomas\\AppData\\Roaming" nil p Dir::LOCAL_APPDATA "C:\\Users\\Thomas\\AppData\\Local" nil
-
@thomthom said:
[ruby]require 'win32dir.rb'
Where do you get 'win32dir.rb' ??
Looks like a Windows extension to the Dir base class. -
I'm almost sure it is from win32utils, but it must be an earlier version because the current version of the file has changed considerably.
The current version has a list of dependencies on other libraries, while this version only requires win32api.so
I've attached the version here that relies only on win32api.so
I'd be interested if it returns the localized names of Dir::PERSONAL, et al.
-
I think that on Vista/W7 they changed the windows folder to always be in English, but with an aliasing scheme for presenting them localized to the user in some cases. (I'm a bit confused on how it really is set up.)
But on XP the folder names for sure is localised. I can try later today on my old laptop with Norwegian XP.
-
Hopefully, this file will work. It uses the system call ShGetFolderPath or ShGetSpecialFolerPath to retrieve the folder, so maybe the paths will be localized.
@thomthom said:
But on XP the folder names for sure is localised. I can try later today on my old laptop with Norwegian XP.
I'd be interested to see if it works.
Advertisement