Loading a path

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

On Apr 2, 3:01 pm, “Parv G.” [email protected] wrote:

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.

Anyway i can solve my problem?

-----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 G.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.8 (MingW32)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs