# \_\_PATH\_\_ like \_\_FILE\_\_?

**URL:** <https://www.ruby-forum.com/t/path-like-file/87422>\
**Category:** Ruby\
**Created:** [March 2, 2007, 2:55pm UTC](https://www.ruby-forum.com/t/path-like-file/87422 "2007-03-02T14:55:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 2:55pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/1 "2007-03-02T14:55:25Z")

</div>

Hello.  
I’m rather new to Ruby, so please bare with me. I just want to know if  
there is anything similar to **FILE** but which represents either the  
path to the directory which **FILE** lies in, or the **FILE** including  
the full path to the file?

–Deniz D.

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 3:04pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/2 "2007-03-02T15:04:26Z")

</div>

On Mar 2, 2007, at 7:55 AM, Deniz D. wrote:

> Hello.

Hello.

> I’m rather new to Ruby, so please bare with me.

Welcome to Ruby then.

> I just want to know if there is anything similar to **FILE** but  
> which represents either the path to the directory which **FILE**  
> lies in, or the **FILE** including the full path to the file?

Just ask Ruby to expand it for you:

File.expand\_path( **FILE** )

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 3:07pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/3 "2007-03-02T15:07:27Z")

</div>

Le vendredi 02 mars 2007 14:55, Deniz D. a écrit :

> Hello.  
> I’m rather new to Ruby, so please bare with me. I just want to know if  
> there is anything similar to **FILE** but which represents either the  
> path to the directory which **FILE** lies in, or the **FILE** including  
> the full path to the file?
> 
> –Deniz D.

You have to use the File.expand\_path to do this :

File.expand\_path( **FILE** )  
File.dirname(File.expand\_path( **FILE** ))

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/4 "2007-03-02T15:13:27Z")

</div>

On 3/2/07, Deniz D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello.  
> I’m rather new to Ruby, so please bare with me. I just want to know if  
> there is anything similar to **FILE** but which represents either the  
> path to the directory which **FILE** lies in, or the **FILE** including  
> the full path to the file?
> 
> –Deniz D.

Deniz;

Take a look at the ‘pathname’ library included with ruby:

[http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pathname.html](http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pathname.html)

You should be able to get all that information by combining it with  
**FILE** :

```
path = Pathname.new( __FILE__ )
p path.dirname
p path.expand_path

# ...

```

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/5 "2007-03-02T15:18:29Z")

</div>

Olivier R. wrote:

> You have to use the File.expand\_path to do this :
> 
> File.expand\_path( **FILE** )  
> File.dirname(File.expand\_path( **FILE** ))

Or:  
File.expand\_path( **FILE** +’/…’)

😉

Daniel

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 3:27pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/6 "2007-03-02T15:27:30Z")

</div>

On Mar 2, 8:55 am, Deniz D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello.  
> I’m rather new to Ruby, so please bare with me. I just want to know if  
> there is anything similar to **FILE** but which represents either the  
> path to the directory which **FILE** lies in, or the **FILE** including  
> the full path to the file?

I suggested the same a while back as **DIR**. I too think it would be  
a good thing to have.

T.

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/7 "2007-03-02T15:15:29Z")

</div>

Olivier R. wrote:

> File.expand\_path( **FILE** )  
> File.dirname(File.expand\_path( **FILE** ))

Thanks to both of you.

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/8 "2007-03-02T16:16:34Z")

</div>

On 3/3/07, Daniel DeLorme [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Daniel

Or even:

File.expand\_path(‘…’, **FILE** )

Oh, the choices!

George.

---

<div class="post-metadata">

**Author:** ![Deniz\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@Deniz\_D](https://www.ruby-forum.com/u/Deniz_D)\
**Post date:** [March 2, 2007, 8:29pm UTC](https://www.ruby-forum.com/t/path-like-file/87422/9 "2007-03-02T20:29:17Z")

</div>

On Sat, Mar 03, 2007 at 12:15:31AM +0900, George O. wrote:

> > 😉
> > 
> > Daniel
> 
> Or even:
> 
> File.expand\_path(’…’, **FILE** )

Ooh, that one’s pretty.
