Loading a path

P

Parv G.

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
 
T

Trans

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.
 
P

Phillip Gawlowski

-----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.mozdev.org

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top