Is there a simpler way to get the absolute path of the current script?
path = File.dirname(File.expand_path(FILE))
File.dirname(FILE) by itself can return a relative or absolute path.
Joe
Is there a simpler way to get the absolute path of the current script?
path = File.dirname(File.expand_path(FILE))
File.dirname(FILE) by itself can return a relative or absolute path.
Joe
On Wed, 25 Oct 2006, Joe R. MUDCRAP-CE wrote:
Is there a simpler way to get the absolute path of the current script?
path = File.dirname(File.expand_path(FILE))
File.dirname(FILE) by itself can return a relative or absolute path.
Joe
just a note, what you have above is not the dir for the current script,
it’s
the dir for the current file - eg the value will be the same whether the
file
is run or required/loaded. for the current script you need
path = File.dirname(File.expand_path($0))
or
File.dirname($0)
-a
[email protected] wrote:
File.dirname($0)
I think the main problem is that the second solution is not an abs path
if you type “./script” or even “…/…/bin/script”.
Your first suggestion is what I would use personally.
-Nate
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs