Ferenc Engard wrote:
> Joel VanderWerf wrote:
> 
>>Ferenc Engard wrote:
>>
>>>Hi all,
>>>
>>>I have a library-like script, which can be used from many apps, from
>>>many directories. I need to get the absolute path of the (required)
>>>script file, so, for example, I can always find a file which is in the
>>>same directory where my library script is. Is there a way to do this?
>>
>> From within the script file itself, you can get it with
>>
>>   File.expand_path(__FILE__)
>>
>>So for instance, you might do
>>
>>   abs_path = File.expand_path(__FILE__)
>>   abs_dir = File.dirname(abs_path)
>>
>>But that doesn't help if you access the script using
>>
>>   require 'my-script'
> 
> 
> Er, why not? I have made some experiments, so it seems that it is always

I meant that __FILE__ only gives you the path to the script when 
__FILE__ is referenced in the script itself. Sorry for the confusion.

> true that on the start of my (required) scriptfile, the
> 'File.expand_path(__FILE__)' always returns the absolute path to the
> file, at least the following seems to work:
> 
> # start of my library script, which is included by other files...
> module MOD_LIB
>   SCRIPTDIR=File.split(File.expand_path(__FILE__))[0]
> end
> # ...
> 
> After that, I can use MOD_LIB::SCRIPTDIR to find files which are in the
> same directory as the libary script itself. Or not?

Yeah, that's basically what I was trying to say :)

> Thanks for the help:

Y'r welcome!

> Ferenc
>