Profile-independent directory specification for NT?

12 messages in this thread from ruby-talk in 2004-02

  1.   Moran, Craig M (BAH) <MoranCM@na...mil> 02-25 13:03
  2.   Jim Bob <none@in...com> 02-25 15:59
  3.   Austin Ziegler <austin@ha...ca> 02-25 16:09
  4.   Moran, Craig M (BAH) <MoranCM@na...mil> 02-25 16:38
  5.   Austin Ziegler <austin@ha...ca> 02-25 17:26
  6.   Moran, Craig M (BAH) <MoranCM@na...mil> 02-25 18:05
  7.   Florian G. Pflug <fgp@ph...org> 02-25 19:48
  8.   djberg96@ho...com (Daniel Berger) 02-26 03:05
  9.   eg <eg@jn...jnk> 02-27 10:19
  10.   KUSUNOSE Toru <kusunose@hc...jp> 02-28 09:34
  11.   missing
  12.   wsdng@on...de (Sascha D?rdelmann) 03-01 09:39
  13.   hatespyware@ya...com (anon luker) 02-28 13:54

Moran, Craig M (BAH) <MoranCM@na...mil>

2004-02-25 13:03:51
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

Jim Bob <none@in...com>

2004-02-25 15:59:47
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.

Austin Ziegler <austin@ha...ca>

2004-02-25 16:09:23
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
profile_path = "#{ENV['USERPROFILE']}\\My Documents\\"

-austin
--
austin ziegler    * austin@ha...ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.02.25
                                         * 11.08.25

Moran, Craig M (BAH) <MoranCM@na...mil>

2004-02-25 16:38:25
Thanks!  This works perfectly.  However, Austin's solution does not.  I'd
imagine it was a misplaced quote.  Is either style preferable over the
other?
Craig

-----Original Message-----
From: Jim Bob [mailto:none@in...com]
Sent: Wednesday, February 25, 2004 11:00 AM
To: ruby-talk@ru...org
Subject: Re: Profile-independent directory specification for NT?


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.

          

Austin Ziegler <austin@ha...ca>

2004-02-25 17:26:43
On Thu, 26 Feb 2004 01:38:25 +0900, Moran, Craig M (BAH) wrote:
> Thanks!  This works perfectly.  However, Austin's solution does not.  I'd
> imagine it was a misplaced quote.  Is either style preferable over the
> other? Craig
I just tried my version in Windows XP with irb and it produced the exact 
result.

With the version provided by Jim Bob, you get a string, create a string, and 
then add them to a new string. With mine, you're only creating one string 
through.

irb(main):030:0> profile_path = "#{ENV['USERPROFILE']}\\My Documents\\"
=> "C:\\Documents and Settings\\Austin\\My Documents\\"

-austin
--
austin ziegler    * austin@ha...ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.02.25
                                         * 12.21.29

Moran, Craig M (BAH) <MoranCM@na...mil>

2004-02-25 18:05:45
My bad.  I did #ENV{ instead of #{ENV.  It behaves correctly now.  I
appreciate the explanation.
Craig

-----Original Message-----
From: Austin Ziegler [mailto:austin@ha...ca]
Sent: Wednesday, February 25, 2004 12:27 PM
To: ruby-talk@ru...org
Subject: Re: Profile-independent directory specification for NT?


On Thu, 26 Feb 2004 01:38:25 +0900, Moran, Craig M (BAH) wrote:
> Thanks!  This works perfectly.  However, Austin's solution does not.  I'd
> imagine it was a misplaced quote.  Is either style preferable over the
> other? Craig

I just tried my version in Windows XP with irb and it produced the exact 
result.

With the version provided by Jim Bob, you get a string, create a string, and

then add them to a new string. With mine, you're only creating one string 
through.

irb(main):030:0> profile_path = "#{ENV['USERPROFILE']}\\My Documents\\"
=> "C:\\Documents and Settings\\Austin\\My Documents\\"

-austin
--
austin ziegler    * austin@ha...ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.02.25
                                         * 12.21.29

          

Florian G. Pflug <fgp@ph...org>

2004-02-25 19:48:50
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).

greetings, Florian Pflug

djberg96@ho...com (Daniel Berger)

2004-02-26 03:05:31
"Florian G. Pflug" <fgp@ph...org> wrote in message news:<20040225194848.GA24254@fo...com>...
> 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 ;-) ).
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
Florian G. Pflug 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).
> 
> 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.

KUSUNOSE Toru <kusunose@hc...jp>

2004-02-28 09:34:33
Hi,

In message <20040225194848.GA24254@fo...com>,
"Florian G. Pflug" <fgp@ph...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@hc...jp

This message appeared in a previous month, was never archived, or was lost.

wsdng@on...de (Sascha D?rdelmann)

2004-03-01 09:39:51
KUSUNOSE Toru <kusunose@hc...jp> wrote:
> Using Windows Scripting Host, you can do:
> 
> require 'win32ole'
> shell = WIN32OLE.new("WScript.Shell")
> ProfilePath = shell.specialFolders("MyDocuments")
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

hatespyware@ya...com (anon luker)

2004-02-28 13:54:47
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@na...mil> wrote in message news:<B9500E218FB4D2119DE30000F810BBBF0F1176A9@ne...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

12 messages in this thread from ruby-talk in 2004-02