# How to get the path to module dir?

**URL:** <https://discourse.julialang.org/t/how-to-get-the-path-to-module-dir/15110>\
**Category:** General Usage\
**Created:** [September 18, 2018, 5:43am UTC](https://discourse.julialang.org/t/how-to-get-the-path-to-module-dir/15110 "2018-09-18T05:43:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Post date:** [September 18, 2018, 5:43am UTC](https://discourse.julialang.org/t/how-to-get-the-path-to-module-dir/15110/1 "2018-09-18T05:43:49Z")

</div>

In the module I need to open a file located in the same directory, so I do

`fd = open("foo.txt")`

But when I use the module from another directory, it complains that “foo.txt” does not exist. So, how can I specify a path to the module definition directory?

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [September 18, 2018, 5:50am UTC](https://discourse.julialang.org/t/how-to-get-the-path-to-module-dir/15110/2 "2018-09-18T05:50:20Z")

</div>

`joinpath(dirname(pathof(MyModule)), "foo.txt")`
