tags:

views:

653

answers:

4

Hi

How do I get the directory where the rakefile.rb is located?

I want to use this as my root directory to locate everything off.

Cheers

+1  A: 

If this is a RoR app your Rakefile.rb should be in your RAILS_ROOT directory. So in any script you can specify file location like

 config.load_paths += %W( #{RAILS_ROOT}/extras )
TonyLa
+9  A: 

use __FILE__ to get the file name then you can get the directory from there:

in test.rb

puts __FILE__

output:

/users/foo/test.rb

__FILE__ resolves to the full path of the file it is in.

Use this to get the dir name:

File.dirname(__FILE__)
craigb
+2  A: 

You can get it by calling application.original_dir method. In task you can achieve application object using application method on task object.

Artem Tikhomirov
+4  A: 

Why not just use Dir.pwd

?

Gordon Hartley
The problem with that is that you might invoke the rakefile from some other directory like: $rake -f subdir/rakefile and you may want the path where the rakefile exists because you may need other dependencies available there. Using Dir.pwd would give you the current working dir but that wouldn't be where your other dependencies live (say you've got jar files, for example)
aneccodeal