PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Cross-platform Home Directory?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Cross-platform Home Directory?

Réponse
 
LinkBack Outils de la discussion
Vieux 13/09/2007, 20h19   #1
Trans
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Cross-platform Home Directory?

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.


  Réponse avec citation
Vieux 13/09/2007, 20h37   #2
Joel VanderWerf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cross-platform Home Directory?

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

  Réponse avec citation
Vieux 13/09/2007, 20h49   #3
Daniel Berger
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cross-platform Home Directory?



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


  Réponse avec citation
Vieux 13/09/2007, 20h54   #4
Gordon Thiesfeld
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cross-platform Home Directory?

On 9/13/07, Glen Holcomb <damnbigman@gmail.com> wrote:
> On 9/13/07, Glen Holcomb <damnbigman@gmail.com> wrote:
> >
> > On 9/13/07, Trans <transfire@gmail.com> 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"

  Réponse avec citation
Vieux 14/09/2007, 05h25   #5
Nobuyoshi Nakada
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cross-platform Home Directory?

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

  Réponse avec citation
Vieux 14/09/2007, 06h15   #6
Une Bévue
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cross-platform Home Directory?

Joel VanderWerf <vjoel@path.berkeley.edu> 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
  Réponse avec citation
Vieux 14/09/2007, 07h34   #7
Phil
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cross-platform Home Directory?



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

[mailto:unbewusst.sein@wortanschahung.com.invalid]
> 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


  Réponse avec citation
Vieux 14/09/2007, 14h03   #8
Olivier Renaud
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cross-platform Home Directory?

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h42.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14172 seconds with 16 queries