# Mktempdir() should provide scope to declare a prefix

**URL:** <https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020>\
**Category:** Internals & Design\
**Created:** [July 22, 2017, 3:32pm UTC](https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020 "2017-07-22T15:32:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)\
**Post date:** [July 22, 2017, 3:32pm UTC](https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020/1 "2017-07-22T15:32:01Z")

</div>

Hi All,

I think it may help if mktempdir() can provide an option of a prefix very similar to you can do with mkdtemp in posix. This provides the module developers to create temp directories with their own prefix which can help them able to track the directories created by them than everything starting with tmp or jl\_ prefix.

regards,

Sambit

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 22, 2017, 3:56pm UTC](https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020/2 "2017-07-22T15:56:57Z")

</div>

You can already do that by providing the parent directory.

---

<div class="post-metadata">

**Author:** ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)\
**Post date:** [July 22, 2017, 6:50pm UTC](https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020/3 "2017-07-22T18:50:55Z")

</div>

@yuyichao

While providing a parent directory is a workaround, a third party application or user can technically create the same directory and assign it a non-rwx access control for the Julia process. This can lead to a denial of service on a multi-user system. Ideally, mktempdir() should never fail unless there is no hard disk or user has a quota restriction etc. not the directory is existing.

If the tmp parent has to be a random directory with mktempdir() the module may need to persist the value in between sessions which may unnecessarily increase housekeeping. Hence, prefix for mktempdir() has some intrinsic benefits.

regards,

Sambit

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [July 22, 2017, 10:27pm UTC](https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020/4 "2017-07-22T22:27:32Z")

</div>

I agree with you that adding a prefix can be useful. It turns out [a pull request](https://github.com/JuliaLang/julia/pull/13969) has been opened more than a year ago to support custom suffixes, but it was closed because the Windows API doesn’t support them. It does support prefixes though (but it only uses up to three characters). So we could keep `"tmp"` as the default prefix, but allow changing it to anything else.

Could you file an issue? If you feel like it, you could take inspiration from that old pull request to implement support for custom prefixes.

---

<div class="post-metadata">

**Author:** ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)\
**Post date:** [July 23, 2017, 6:47am UTC](https://discourse.julialang.org/t/mktempdir-should-provide-scope-to-declare-a-prefix/5020/5 "2017-07-23T06:47:52Z")

</div>

Issue created: [https://github.com/JuliaLang/julia/issues/22922](https://github.com/JuliaLang/julia/issues/22922)
