[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Loading a path

Parv G.

4/2/2008 7:01:00 PM

I'm trying to read/write a text file.
code:

$LOAD_PATH << "c:/path/to/resource/folder"
file = File.new('resources/testResults.txt', "a")
file.puts results

I keep on getting an error: "...in `initialize': No such file or
directory - ./resources/TestResults.txt (Errno::ENOENT)", when i run
this file from SciTE (the editor that comes with ruby on windows, BUT
when i run this from eclipse (RDT) the script works just fine.

I really would like to avoid mixing in full file paths in my code.
Can somebody offer some suggestions?
Why isn't $LOAD_PATH working for me, even though i see the path i need
in $LOAD_PATH?

Thanks,
Parv
--
Posted via http://www.ruby-....

3 Answers

Trans

4/2/2008 7:07:00 PM

0



On Apr 2, 3:01 pm, "Parv G." <ghotr...@yahoo.com> wrote:
> I'm trying to read/write a text file.
> code:
>
> $LOAD_PATH << "c:/path/to/resource/folder"
> file = File.new('resources/testResults.txt', "a")
> file.puts results
>
> I keep on getting an error: "...in `initialize': No such file or
> directory - ./resources/TestResults.txt (Errno::ENOENT)", when i run
> this file from SciTE (the editor that comes with ruby on windows, BUT
> when i run this from eclipse (RDT) the script works just fine.
>
> I really would like to avoid mixing in full file paths in my code.
> Can somebody offer some suggestions?
> Why isn't $LOAD_PATH working for me, even though i see the path i need
> in $LOAD_PATH?

$LOAD_PATH only works for #require and #load. It has no effect on
File.new.

T.

Parv G.

4/2/2008 7:23:00 PM

0

Anyway i can solve my problem?
--
Posted via http://www.ruby-....

Phillip Gawlowski

4/3/2008 5:31:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Parv G. wrote:
| Anyway i can solve my problem?

$MY_PATH = "c:/path/to/resource/folder"
file = File.new("#{MY_PATH}/resources/testResults.txt", "a")
file.puts results

This example uses String evaluation, and should work. I haven't tested
it, though, so YMMV.

- -- Phillip Gawlowski
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail....

iEYEARECAAYFAkf0a44ACgkQbtAgaoJTgL+D1ACdEjwv5N0PYqXxUKk3jasrYhkn
8GMAoKIsV99a+KpH2U9KNYSsJpIM1K4A
=CMT+
-----END PGP SIGNATURE-----