# Rakefile "$0" path in rake

**URL:** <https://www.ruby-forum.com/t/rakefile-0-path-in-rake/157600>\
**Category:** Ruby\
**Created:** [January 13, 2009, 3:58pm UTC](https://www.ruby-forum.com/t/rakefile-0-path-in-rake/157600 "2009-01-13T15:58:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@peterk](https://www.ruby-forum.com/u/peterk)\
**Post date:** [January 13, 2009, 3:58pm UTC](https://www.ruby-forum.com/t/rakefile-0-path-in-rake/157600/1 "2009-01-13T15:58:43Z")

</div>

Is there a way to get the path to “itself” in a rakefile loaded by rake?

ie for:  
rake --rakefile …/…/some/path/to/rakefile.rb

* * *

inside rakefile

myPath = # ???  
p “running #{myPath}”

---

<div class="post-metadata">

**Author:** ![peterk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@peterk](https://www.ruby-forum.com/u/peterk)\
**Post date:** [January 13, 2009, 4:03pm UTC](https://www.ruby-forum.com/t/rakefile-0-path-in-rake/157600/2 "2009-01-13T16:03:54Z")

</div>

Peter Pk schrieb:

> p “running #{myPath}”  
> try using the “magic variable” **FILE**?

---

<div class="post-metadata">

**Author:** ![peterk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@peterk](https://www.ruby-forum.com/u/peterk)\
**Post date:** [January 13, 2009, 4:05pm UTC](https://www.ruby-forum.com/t/rakefile-0-path-in-rake/157600/3 "2009-01-13T16:05:44Z")

</div>

On Jan 13, 2009, at 8:57 AM, Peter Pk wrote:

> Is there a way to get the path to “itself” in a rakefile loaded by  
> rake?

Sure.

> * * *
> 
> inside rakefile
> 
> myPath = # ???

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

> p “running #{myPath}”

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![peterk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7993a0/32.png) [@peterk](https://www.ruby-forum.com/u/peterk)\
**Post date:** [January 13, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/rakefile-0-path-in-rake/157600/4 "2009-01-13T16:37:36Z")

</div>

badboy wrote:

> Peter Pk schrieb:
> 
> > p “running #{myPath}”  
> > try using the “magic variable” **FILE**?

Thanks! Thats it!
