Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake and current directory

Tags:

ruby

rake

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.

like image 839
dagda1 Avatar asked Oct 25 '08 15:10

dagda1


2 Answers

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__) 
like image 52
craigb Avatar answered Sep 25 '22 23:09

craigb


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

like image 41
Artem Tikhomirov Avatar answered Sep 22 '22 23:09

Artem Tikhomirov