How to find directory of currently running .rb file


#1

FILE is just giving me the file name, with no path, and Dir.getwd
is giving me an error: “ENOENT: No such file or directory.” What is
the proper way to get this info?

Thanks in advance,
Ken McDonald


#2

On Mon Oct 27 19:01:04 2008, Kenneth McDonald wrote:

FILE is just giving me the file name, with no path, and Dir.getwd is
giving me an error: “ENOENT: No such file or directory.” What is the proper
way to get this info?

FILE gives you the path it was called with, if your Ruby script is
in the current working directory it will return “./foo.rb” if it is in
/usr/local/bin FILE will be “/usr/local/bin/foo.rb”. If you want
the full path instead of “./” Dir.getwd should work.


#3

Kenneth McDonald wrote:

FILE is just giving me the file name, with no path, and Dir.getwd
is giving me an error: “ENOENT: No such file or directory.” What is
the proper way to get this info?

File.dirname(FILE)