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…
Peter V. 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,
Peter V. 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(".")
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!
Janus B. wrote:
p Dir.entries(".") #array containing files in current directory
putsWill 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
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!
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 H. wrote:
Peter V. 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,