From: Christopher Aldridge Date: 2005-08-25T11:23:11+09:00 Subject: Re: OS independent way to read/write paths? Cool! Thanks for sharing the correct way of doing it :-) On 8/24/05, Daniel Berger wrote: > Christopher Aldridge wrote: > > to determine how to handle the path, I use something as such: > > > > require 'rbconfig' > > include Config > > > > home = "c:/documents and settings/username" if CONFIG['host'].match("mswin") > > home = "/home/username" if CONFIG['host'].match("solaris") ##for > > solaris nix box > > > > system("echo hello > #{home}/.txt") > > > > The forward slashes usually work for windows in most cases but.... > > hope this helps.. > > I'm going OT here, but... > > First, you don't need rbconfig. Just check against PLATFORM, e.g. if > PLATFORM.match("mswin"). > > Second, I would use ENV["HOME"] || ENV["USERPROFILE"] over a hard coded home > directory on Windows. > > Third, on Unix platforms, you can generally rely on ENV["HOME"]. If not, you > can always use the etc or sys-admin package, e.g. > > Admin.get_user(Admin.get_login).dir > > Actually, you can do the same thing on Windows, though it usually isn't set > locally (and you probably don't want the global home directory), e.g. > > Admin.get_user(Admin.get_login).home_dir > > Regards, > > Dan > >