Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Cross-platform Home Directory?

Reply
Thread Tools

Cross-platform Home Directory?

 
 
Trans
Guest
Posts: n/a
 
      09-13-2007
I have a little app that needs to store session data. I assume the
best place to store it is in one's home directory, but I need this app
to be cross-platform. I glanced through all rbconfig.rb's
Config::CONFIG settings but did not see anything for it. How does one
access a cross-platform home directory?

Thanks,
T.


 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      09-13-2007
Trans wrote:
> I have a little app that needs to store session data. I assume the
> best place to store it is in one's home directory, but I need this app
> to be cross-platform. I glanced through all rbconfig.rb's
> Config::CONFIG settings but did not see anything for it. How does one
> access a cross-platform home directory?


This is one way of guessing:

case RUBY_PLATFORM
when /win32/
ENV['APPDATA'] ||
ENV['USERPROFILE'] ||
ENV['HOME']

else
ENV['HOME'] ||
File.expand_path('~')
end

Typical values:

ENV['APPDATA'] == "C:\Documents and Settings\username\Application Data"
ENV['USERPROFILE'] == "C:\Documents and Settings\username"

(This is from my 'preferences' lib.)

I have no idea what is right on OS X. I'm sure someone has thought this
through in more detail...

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 
Reply With Quote
 
 
 
 
Daniel Berger
Guest
Posts: n/a
 
      09-13-2007


On Sep 13, 1:37 pm, Joel VanderWerf <vj...@path.berkeley.edu> wrote:
> Trans wrote:
> > I have a little app that needs to store session data. I assume the
> > best place to store it is in one's home directory, but I need this app
> > to be cross-platform. I glanced through all rbconfig.rb's
> > Config::CONFIG settings but did not see anything for it. How does one
> > access a cross-platform home directory?

>
> This is one way of guessing:


<snip>

I think the appdata directory is where you want it for MS Windows. You
can use win32-dir, since the environment variable may not be defined:

when /mswin/
require 'win32/dir'
Dir::APPDATA

Regards,

Dan


 
Reply With Quote
 
Gordon Thiesfeld
Guest
Posts: n/a
 
      09-13-2007
On 9/13/07, Glen Holcomb <> wrote:
> On 9/13/07, Glen Holcomb <> wrote:
> >
> > On 9/13/07, Trans <> wrote:
> > >
> > > I have a little app that needs to store session data. I assume the
> > > best place to store it is in one's home directory, but I need this app
> > > to be cross-platform. I glanced through all rbconfig.rb's
> > > Config::CONFIG settings but did not see anything for it. How does one
> > > access a cross-platform home directory?
> > >
> > > Thanks,
> > > T.



Rubygems has a method for finding this:

C:\>irb -rubygems
>> Gem.user_home

=> "C:\\Documents and Settings\\gthiesfeld"

 
Reply With Quote
 
Nobuyoshi Nakada
Guest
Posts: n/a
 
      09-14-2007
Hi,

At Fri, 14 Sep 2007 04:19:04 +0900,
Trans wrote in [ruby-talk:268970]:
> I have a little app that needs to store session data. I assume the
> best place to store it is in one's home directory, but I need this app
> to be cross-platform. I glanced through all rbconfig.rb's
> Config::CONFIG settings but did not see anything for it. How does one
> access a cross-platform home directory?


There is no static value.

FYI, in 1.9, if ENV["HOME"] isn't set, it will be set to
1) ENV["HOMEDRIVE"] + ENV["HOMEPATH"]
2) ENV["USERPROFILE"] or
3) "Personal" special folder
in the above order.

--
Nobu Nakada

 
Reply With Quote
 
Une Bévue
Guest
Posts: n/a
 
      09-14-2007
Joel VanderWerf <> wrote:

> I have no idea what is right on OS X.


ENV[ 'HOME' ]

for example my "home" is :

/Users/yt

(never tried the File.expand_path('~') ) BUT on Mac OS X shell ~ expand
to home.

also i worry about the way win* representent pathes with \

does that means that, in ruby, there is no platform-independant way to
representant pathes, as, for example in Java ?
--
La politique est l'art d'empécher les gens
de se méler de ce qui les regarde.
Paul Valéry
 
Reply With Quote
 
Phil
Guest
Posts: n/a
 
      09-14-2007


> -----Original Message-----
> From: "Une B=E9v" "ue" =

[private.php?do=newpm&u=]
> Sent: Friday, September 14, 2007 7:20 AM
> To: ruby-talk ML
> Subject: Re: Cross-platform Home Directory?
>=20
> does that means that, in ruby, there is no platform-independant way to
> representant pathes, as, for example in Java ?



8:31:09.25 C:\Users\CynicalRyan
>ls gems.txt

gems.txt

8:31:14.01 C:\Users\CynicalRyan
>irb --simple-prompt
>> File.open("c:/Users/CynicalRyan/gems.txt")

=3D> #<File:c:/Users/CynicalRyan/gems.txt>

>ruby -v

ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

>ver


Microsoft Windows [Version 6.0.6000]

--
Phillip Gawlowski


 
Reply With Quote
 
Olivier Renaud
Guest
Posts: n/a
 
      09-14-2007
Trans a écrit :
> I have a little app that needs to store session data. I assume the
> best place to store it is in one's home directory, but I need this app
> to be cross-platform. I glanced through all rbconfig.rb's
> Config::CONFIG settings but did not see anything for it. How does one
> access a cross-platform home directory?
>
> Thanks,
> T.
>

This is how I do this :
home_directory = Dir.chdir {|path| path}

The doc for Dir.chdir says that without argument, this method looks for
environnement variables HOME or LOGDIR. And with a block, the directory
is changed only inside the block, and restored right after.

--
Olivier Renaud

 
Reply With Quote
 
micathom
Guest
Posts: n/a
 
      09-14-2007
> case RUBY_PLATFORM
> when /win32/
> ENV['APPDATA'] ||
> ENV['USERPROFILE'] ||
> ENV['HOME']


As HOME usually isn't set on windows, the existence of the variable
could indicate that the user would like to override the windows
default. I would thus check for HOME first.

Also, under cygwin ruby all three variables are set, but APPDATA and
USERPROFILE are "inherited" from the windows environment and are by
default set as Windows path while HOME usually is set as cygwin path.
In certain situations, this could cause certain difficulties, eg when
calling external programs.

It seems the trick with chdir doesn't work when neither HOME nor
LOGDIR is set -- as it is usually the case under Windows, I think.

 
Reply With Quote
 
Clifford Heath
Guest
Posts: n/a
 
      09-15-2007
Trans wrote:
> I have a little app that needs to store session data. I assume the
> best place to store it is in one's home directory


Everyone's helped you with ways to find the home directory, but on Windows
this is not normally the right place to store session data. That's what
Application Data is for. Make a directory under there for your application.
Configuration data (user-modifiable but less frequently-changing) may be
stored in the registry.

The Windows certification documents describe where you should put stuff.

Clifford Heath.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XP home SP2 cannot view/access my XP home SP1 or my Win2K machines =?Utf-8?B?SmFtaW5h?= Wireless Networking 3 02-15-2006 02:18 AM
How To Connect Your PC to Your Home Stereo or Home Theater Silverstrand Front Page News 0 12-08-2005 01:29 PM
Home Network - XP Home Edition and Windows 2000 =?Utf-8?B?UEFS?= Wireless Networking 1 12-30-2004 09:40 PM
Set up home a home or small office network!!!! Chris Jardine Computer Support 2 04-06-2004 02:28 AM
When I open Internet Explorer, along with my home page a pop page pops up, I have changed home page but that doesnt work Phil Computer Support 7 03-04-2004 12:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57