# How to find directory of currently running .rb file

**URL:** <https://www.ruby-forum.com/t/how-to-find-directory-of-currently-running-rb-file/151909>\
**Category:** Ruby\
**Created:** [October 27, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/how-to-find-directory-of-currently-running-rb-file/151909 "2008-10-27T20:02:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 27, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/how-to-find-directory-of-currently-running-rb-file/151909/1 "2008-10-27T20:02:16Z")

</div>

**FILE** is just giving me the file name, with no path, and Dir.getwd  
is giving me an error: “ENOENT: No such file or directory.” What is  
the proper way to get this info?

Thanks in advance,  
Ken McDonald

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 27, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/how-to-find-directory-of-currently-running-rb-file/151909/2 "2008-10-27T20:21:39Z")

</div>

On Mon Oct 27 19:01:04 2008, Kenneth McDonald wrote:

> **FILE** is just giving me the file name, with no path, and Dir.getwd is  
> giving me an error: “ENOENT: No such file or directory.” What is the proper  
> way to get this info?

**FILE** gives you the path it was called with, if your Ruby script is  
in the current working directory it will return â€œ./foo.rbâ€ if it is in  
/usr/local/bin **FILE** will be â€œ/usr/local/bin/foo.rbâ€. If you want  
the full path instead of â€œ./â€ Dir.getwd should work.

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [October 27, 2008, 10:18pm UTC](https://www.ruby-forum.com/t/how-to-find-directory-of-currently-running-rb-file/151909/3 "2008-10-27T22:18:36Z")

</div>

Kenneth McDonald wrote:

> **FILE** is just giving me the file name, with no path, and Dir.getwd  
> is giving me an error: “ENOENT: No such file or directory.” What is  
> the proper way to get this info?

File.dirname( **FILE** )
