# Loading a path

**URL:** <https://www.ruby-forum.com/t/loading-a-path/133705>\
**Category:** Ruby\
**Created:** [April 2, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/loading-a-path/133705 "2008-04-02T21:01:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![parvg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@parvg](https://www.ruby-forum.com/u/parvg)\
**Post date:** [April 2, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/loading-a-path/133705/1 "2008-04-02T21:01:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![parvg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@parvg](https://www.ruby-forum.com/u/parvg)\
**Post date:** [April 2, 2008, 9:07pm UTC](https://www.ruby-forum.com/t/loading-a-path/133705/2 "2008-04-02T21:07:27Z")

</div>

On Apr 2, 3:01 pm, “Parv G.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![parvg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@parvg](https://www.ruby-forum.com/u/parvg)\
**Post date:** [April 2, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/loading-a-path/133705/3 "2008-04-02T21:23:17Z")

</div>

Anyway i can solve my problem?

---

<div class="post-metadata">

**Author:** ![parvg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@parvg](https://www.ruby-forum.com/u/parvg)\
**Post date:** [April 3, 2008, 7:32am UTC](https://www.ruby-forum.com/t/loading-a-path/133705/4 "2008-04-03T07:32:20Z")

</div>

-----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](http://enigmail.mozdev.org)

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