# How to generate/create a new file in the same folder of a function?

**URL:** <https://discourse.julialang.org/t/how-to-generate-create-a-new-file-in-the-same-folder-of-a-function/71217>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 9, 2021, 7:04pm UTC](https://discourse.julialang.org/t/how-to-generate-create-a-new-file-in-the-same-folder-of-a-function/71217 "2021-11-09T19:04:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [November 9, 2021, 7:04pm UTC](https://discourse.julialang.org/t/how-to-generate-create-a-new-file-in-the-same-folder-of-a-function/71217/1 "2021-11-09T19:04:30Z")

</div>

I know that the below code will create `record.txt` it in the default directory of julia.

```julia
io = open("record.txt", "w")
close(io)

```

However, I have a function called `Myfile` (in which I will share it with others). So, I need to add in it a code to create a `record.txt` in its folder (since I dont know in future in which directory it will be located), How can I do that?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [November 9, 2021, 7:31pm UTC](https://discourse.julialang.org/t/how-to-generate-create-a-new-file-in-the-same-folder-of-a-function/71217/2 "2021-11-09T19:31:04Z")

</div>

`@ __DIR__ ` is your friend.

```julia
help?> @ __DIR__
  @ __DIR__ -> AbstractString

  Expand to a string with the absolute path to the directory of the file containing the
  macrocall. Return the current working directory if run from a REPL or if evaluated by
  julia -e <expr>.

```

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [November 9, 2021, 7:41pm UTC](https://discourse.julialang.org/t/how-to-generate-create-a-new-file-in-the-same-folder-of-a-function/71217/4 "2021-11-09T19:41:26Z")

</div>

Thank you very much!
