[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting path of current script

Joe Ruby

10/24/2006 6:06:00 PM

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

--
Posted via http://www.ruby-....

2 Answers

Ara.T.Howard

10/24/2006 6:28:00 PM

0

Nate Wiger

10/24/2006 6:37:00 PM

0

ara.t.howard@noaa.gov wrote:
>
> 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)

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