[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie question - how to get current directory into a variab

Peter Vanderhaden

10/15/2007 11:53:00 PM

I'm running Ruby on Ubuntu Linux, and I need to be able to get the
current directory that the program is running in into a variable in my
program. Is there a simple way to do this? Also, is there a way to
change directories within the program?
Thanks....
--
Posted via http://www.ruby-....

6 Answers

Tim Hunter

10/16/2007 12:25:00 AM

0

Peter Vanderhaden wrote:
> I'm running Ruby on Ubuntu Linux, and I need to be able to get the
> current directory that the program is running in into a variable in my
> program. Is there a simple way to do this? Also, is there a way to
> change directories within the program?
> Thanks....

Check out the Dir class, particularly Dir.pwd and Dir.chdir,

--
RMagick OS X Installer [http://rubyforge.org/project...]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]

Peter Vanderhaden

10/16/2007 12:37:00 AM

0

Thanks Tim. the Dir.pwd is exactly what I need. I haven't figured out
how to use the Dir.chdir yet, but that looks promising too.
PV
Tim Hunter wrote:
> Peter Vanderhaden wrote:
>> I'm running Ruby on Ubuntu Linux, and I need to be able to get the
>> current directory that the program is running in into a variable in my
>> program. Is there a simple way to do this? Also, is there a way to
>> change directories within the program?
>> Thanks....
>
> Check out the Dir class, particularly Dir.pwd and Dir.chdir,

--
Posted via http://www.ruby-....

7stud --

10/16/2007 3:43:00 AM

0

Peter Vanderhaden wrote:
> Thanks Tim. the Dir.pwd is exactly what I need. I haven't figured out
> how to use the Dir.chdir yet, but that looks promising too.

p Dir.entries(".") #array containing files in current directory
puts

Dir.chdir("../") #relative path
p Dir.entries(".")
puts

Dir.chdir("/Users/me/Documents/ruby") #absolute path
p Dir.entries(".")

--
Posted via http://www.ruby-....

Janus Bor

7/14/2008 12:08:00 PM

0

Sorry for raising this thread from the dead!

7stud -- wrote:
> p Dir.entries(".") #array containing files in current directory
> puts

Will this work on Windows, too? Or is the "." a Linux specific thing? If
it doesn't work on Windows, how can I get the absolute path of the
scipt? Thanks!

--
Posted via http://www.ruby-....

Dave Bass

7/14/2008 2:44:00 PM

0

Janus Bor wrote:
>> p Dir.entries(".") #array containing files in current directory
>> puts
>
> Will this work on Windows, too? Or is the "." a Linux specific thing?

Works for me (WinXP, Ruby 1.8.6-111).
Both "." and ".." work fine on Windows.

Dave


--
Posted via http://www.ruby-....

Sean Willis

8/28/2008 8:34:00 PM

0

Thought I'd keep this one going!

Using Dir.chdir() I have no problem changing to directories created by
my rails application, however, I can't get it to change to a directory
that I made. I tried adding "config.load_paths += %W(
#{RAILS_ROOT}/public/my_new_folder" to my environment.rb file, but it
didn't work. When should I be using config.load_paths?

Any ideas? Thanks!
--
Posted via http://www.ruby-....