Is there a way to specify a directory in Ruby that is profile-independent
for the Windows NT variants? For example, if I wanted to do this in VBA for
the currently logged in user’s My Documents folder, it would look like this:
ProfilePath = Environ(“USERPROFILE”) & "\My Documents"
This way, regardless of who is logged in and runs the script, it will always
point to their own My Documents folder. Thanks in advance for the help-
Craig
The environment is available under the hash ENV. So, you can do
something like:
ProfilePath = ENV[“USERPROFILE”] + "\My Documents\"
basically like you said you’d do with VBA.
profile_path = “#{ENV[‘USERPROFILE’]}\My Documents\”
-austin
···
On Wed, 25 Feb 2004 22:03:51 +0900, Moran, Craig M (BAH) wrote:
Is there a way to specify a directory in Ruby that is profile-independent
for the Windows NT variants? For example, if I wanted to do this in VBA
for the currently logged in user’s My Documents folder, it would look
like this: ProfilePath = Environ(“USERPROFILE”) & "\My Documents"
This way, regardless of who is logged in and runs the script, it will
always point to their own My Documents folder. Thanks in advance for the
help- Craig
–
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.02.25
* 11.08.25
Be aware that this is only correct on english versions of windows. In german
e.g, the folder is not named “My Documents” but “Meine Dateien” (or
something like that - don’t use windows very often ).
I believe that the windows registry is the right place to get that
information from. (I have to admit though, that I have no idea how you could access
the registry from ruby, and where you find this information there).
greetings, Florian Pflug
···
On Wed, Feb 25, 2004 at 10:03:51PM +0900, Moran, Craig M (BAH) wrote:
Is there a way to specify a directory in Ruby that is profile-independent
for the Windows NT variants? For example, if I wanted to do this in VBA for
the currently logged in user’s My Documents folder, it would look like this:
ProfilePath = Environ(“USERPROFILE”) & "\My Documents"
This way, regardless of who is logged in and runs the script, it will always
point to their own My Documents folder. Thanks in advance for the help-
If you want a profile independent path, then just use an absolute
pathname.
I think that you want a profile dependent path. The most correct
way to get one is with WMI. You will have to peruse the sdk docs to
determine the correct way of finding this pathname for your network
setup, though.
A slightly simpler method that you might try:
require ‘win32ole’
wsh = WIN32OLE.new(“WScript.Shell”)
desktop = wsh.SpecialFolders(“Desktop”)
puts “desktop = ‘#{desktop}’”
This assumes wsh availability (present if you use vba on this
machine).
If you come from a vba background, you should probably get ArtonX’s
excellent activerubyscript package from
http://www.geocities.co.jp/SiliconValley-PaloAlto/9251/ruby/main.html
… It has a wsh<->ruby bridge that lets you use ruby via wsh in ie,
iis, word, and wherever else you would normally use vba. It should
also lower the bar for translating vba to ruby. It is a shame that
the base windows installs don’t provide this functionality, since it
is de rigour for all modern scripting languages (I could be wrong
about its inclusion, but http://rubyinstaller.sourceforge.net tells
you to look at http://rubygarden.org/ruby?WindowsInstaller for a
manifest and vice-versa and I don’t have the patience for such
nonsense).
“Moran, Craig M (BAH)” MoranCM@navair.navy.mil wrote in message news:B9500E218FB4D2119DE30000F810BBBF0F1176A9@nems13.nawcad.navy.mil…
···
Is there a way to specify a directory in Ruby that is profile-independent
for the Windows NT variants? For example, if I wanted to do this in VBA for
the currently logged in user’s My Documents folder, it would look like this:
ProfilePath = Environ(“USERPROFILE”) & "\My Documents"
This way, regardless of who is logged in and runs the script, it will always
point to their own My Documents folder. Thanks in advance for the help-
Craig
“Florian G. Pflug” fgp@phlo.org wrote in message news:20040225194848.GA24254@foobar.solution-x.com…
Is there a way to specify a directory in Ruby that is profile-independent
for the Windows NT variants? For example, if I wanted to do this in VBA for
the currently logged in user’s My Documents folder, it would look like this:
ProfilePath = Environ(“USERPROFILE”) & "\My Documents"
This way, regardless of who is logged in and runs the script, it will always
point to their own My Documents folder. Thanks in advance for the help-
Be aware that this is only correct on english versions of windows. In german
e.g, the folder is not named “My Documents” but “Meine Dateien” (or
something like that - don’t use windows very often ).
In theory, each user has a home directory set. You can see if it’s
set by going to Start → Settings → Control Panel → Users and
Passwords → Advanced → Advanced (again) → Click on users → right
click to view properties → click “Profile” tab.
You can use the win32-etc module to get at this information as well in
a language-neutral way:
require “win32/etc”
include Win32
Etc.passwd{ |s|
p s.name
p s.home_dir
}
Often times, however, this value isn’t set and you have to resort to
environment variables.
I believe that the windows registry is the right place to get that
information from. (I have to admit though, that I have no idea how you could access
the registry from ruby, and where you find this information there).greetings, Florian Pflug
You can use “win32/registry” which ships with 1.8.1. However, there’s
no advantage to using the registry over the environment variable since
the two are identical as far as I know.
Regards,
Dan
···
On Wed, Feb 25, 2004 at 10:03:51PM +0900, Moran, Craig M (BAH) wrote:
Florian G. Pflug wrote:
Is there a way to specify a directory in Ruby that is profile-independent
for the Windows NT variants? For example, if I wanted to do this in VBA for
the currently logged in user’s My Documents folder, it would look like this:
ProfilePath = Environ(“USERPROFILE”) & "\My Documents"
This way, regardless of who is logged in and runs the script, it will always
point to their own My Documents folder. Thanks in advance for the help-Be aware that this is only correct on english versions of windows. In german
e.g, the folder is not named “My Documents” but “Meine Dateien” (or
something like that - don’t use windows very often ).I believe that the windows registry is the right place to get that
information from. (I have to admit though, that I have no idea how you could access
the registry from ruby, and where you find this information there).greetings, Florian Pflug
In Win2K and up you can call a Shell function SHGetFolderPath( ) which
can be used to return this directory.
for example,
SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS,
NULL, 0, szPath)
Alternatively, you can look in the registry in the following branch:
“HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
Folders”
Under Win2K and up, there will be an entry labelled “Personal” which
contains this directory name.
···
On Wed, Feb 25, 2004 at 10:03:51PM +0900, Moran, Craig M (BAH) wrote:
Hi,
In message 20040225194848.GA24254@foobar.solution-x.com,
···
“Florian G. Pflug” fgp@phlo.org wrote:
On Wed, Feb 25, 2004 at 10:03:51PM +0900, Moran, Craig M (BAH) wrote:
Is there a way to specify a directory in Ruby that is profile-independent
for the Windows NT variants? For example, if I wanted to do this in VBA for
the currently logged in user’s My Documents folder, it would look like this:
ProfilePath = Environ(“USERPROFILE”) & "\My Documents"
This way, regardless of who is logged in and runs the script, it will always
point to their own My Documents folder. Thanks in advance for the help-
Be aware that this is only correct on english versions of windows. In german
e.g, the folder is not named “My Documents” but “Meine Dateien” (or
something like that - don’t use windows very often ).I believe that the windows registry is the right place to get that
information from. (I have to admit though, that I have no idea how you could access
the registry from ruby, and where you find this information there).
Using Windows Scripting Host, you can do:
require ‘win32ole’
shell = WIN32OLE.new(“WScript.Shell”)
ProfilePath = shell.specialFolders(“MyDocuments”)
–
KUSUNOSE Toru mailto:kusunose@hcn.zaq.ne.jp
Alternatively you can use the explorer’s “Shell” object:
WIN32OLE.new(‘Shell.application’)
Access to the path is not as easy, though. You need to know some
constants which can be found in the Windows SDK. The good thing about
using those constants is that they are language independent.
Play around with the code at
http://people.freenet.de/wickie/winshell.zip
Cheers
Sascha
···
KUSUNOSE Toru kusunose@hcn.zaq.ne.jp wrote:
Using Windows Scripting Host, you can do:
require ‘win32ole’
shell = WIN32OLE.new(“WScript.Shell”)
ProfilePath = shell.specialFolders(“MyDocuments”)