# File path

**URL:** <https://www.ruby-forum.com/t/file-path/124207>\
**Category:** Ruby\
**Created:** [December 26, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/file-path/124207 "2007-12-26T14:01:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 26, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/file-path/124207/1 "2007-12-26T14:01:13Z")

</div>

Hi,

I needed to know how to find the path of a file at a particulat  
place so that it should effect all the places where its called.

I am hard coding it presently, is there a means of writing this  
path some where and then calling it where ever needed

file = File.open("/home/Ruby\_Files/add.rb",“r”)

Thanking You

ARB

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 27, 2007, 1:56pm UTC](https://www.ruby-forum.com/t/file-path/124207/2 "2007-12-27T13:56:18Z")

</div>

2007/12/26, Advait B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,
> 
> I needed to know how to find the path of a file at a particulat  
> place so that it should effect all the places where its called.
> 
> I am hard coding it presently, is there a means of writing this  
> path some where and then calling it where ever needed
> 
> file = File.open(“/home/Ruby\_Files/add.rb”,“r”)

The usual solution is to put the path into a variable or constant and  
use that instead of literals.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 27, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/file-path/124207/3 "2007-12-27T14:11:33Z")

</div>

Robert K. wrote:

> 2007/12/26, Advait B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Hi,
> > 
> > I needed to know how to find the path of a file at a particulat  
> > place so that it should effect all the places where its called.
> > 
> > I am hard coding it presently, is there a means of writing this  
> > path some where and then calling it where ever needed
> > 
> > file = File.open(“/home/Ruby\_Files/add.rb”,“r”)
> 
> The usual solution is to put the path into a variable or constant and  
> use that instead of literals.
> 
> Cheers
> 
> robert

Hi,

Thank you very much the method of assigning to a variable and then using  
the variable is working perfectly.

Thank you

Advait
