[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Most used pwd in ruby

Sak Na rede

11/29/2008 6:02:00 PM

Hi all!

I have to program a lot of scripts, most of them work with files and
folders. This files and the folders are in the directory of the script,
it works well except if script is called from another directory. I solve
this problem with:

Dir.chdir("complete_path")

I think this solution is not the best for a lot of reasons, how do you
do that?

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

4 Answers

Matthias Hennemeyer

11/29/2008 6:51:00 PM

0

File.dirname(__FILE__) always refers to the current folder.




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

Robert Klemme

11/29/2008 8:10:00 PM

0

On 29.11.2008 19:51, Matthias Hennemeyer wrote:
> File.dirname(__FILE__) always refers to the current folder.

Or rather File.dirname($0) if you want the main script file's directory.
__FILE__ depends on the currently executed file which can be anywhere.

See also "ri Pathname" for other options.

Kind regards

robert

Marc Heiler

11/29/2008 9:02:00 PM

0

> Dir.chdir("complete_path")

It works, but I think it is not a perfect approach. What is better is
to, IMHO, work with absolute paths as much as possible. Ruby on windows
seems to happily accept "/foo/bla" locations so there really is not work
involved for my scripts when I use them on my windows machine (which is
mostly turned off these days)

Aside from that I guess most people here will use relative paths.
--
Posted via http://www.ruby-....

Sak Na rede

11/29/2008 10:06:00 PM

0

Marc Heiler wrote:
>> Dir.chdir("complete_path")
>
> It works, but I think it is not a perfect approach. What is better is
> to, IMHO, work with absolute paths as much as possible. Ruby on windows
> seems to happily accept "/foo/bla" locations so there really is not work
> involved for my scripts when I use them on my windows machine (which is
> mostly turned off these days)
>
> Aside from that I guess most people here will use relative paths.

I'm working in unix system and my scripts will always run in unix but
it's a very important know that. Thanks

Thanks Matthias and robert, very simple and very helpful, perfect!
--
Posted via http://www.ruby-....