# \`tempdir()\` differences in Windows and Linux

**URL:** <https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930>\
**Category:** General Usage\
**Created:** [June 4, 2019, 6:02pm UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930 "2019-06-04T18:02:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [June 4, 2019, 6:02pm UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930/1 "2019-06-04T18:02:33Z")

</div>

Using Julia v1.1.0 on Windows 10, `tempdir()` returns a path with a separator at the end:

julia\> tempdir()  
“C:\Users\mxbiee\AppData\Local\Temp\”

and on Linux, it doesn’t:

julia\> tempdir()  
“/tmp”

This caused some mildly hard-to-track issues when “porting” some Linux-developed code to Windows. I realise that some system differences are hard to avoid, but this one seems a bit arbritrary.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 4, 2019, 6:25pm UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930/2 "2019-06-04T18:25:38Z")

</div>

See [https://github.com/JuliaLang/julia/pull/31434](https://github.com/JuliaLang/julia/pull/31434). How did you use `tempdir()` to cause this problem? If you use e.g. `joinpath` a trailing `/` should not matter I think.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [June 4, 2019, 6:32pm UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930/3 "2019-06-04T18:32:06Z")

</div>

Thanks for the link! I missed that issue (for some reason it doesn’t come up on a search for `tempdir`).

I had some very old test code where I wanted a temporary file with a specific name, something like  
`outfile = "$(tempdir())/specifictest"`  
which works on Linux but not on Windows, which gets confused by the `/`.

Now I’m using `tempname()`.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [June 4, 2019, 6:52pm UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930/4 "2019-06-04T18:52:07Z")

</div>

The `\` problem can be avoided by using `joinpath`/`splitpath` whenever paths are employed. It still requires specific handling whenever reading valid paths generated outside julia.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [June 4, 2019, 7:12pm UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930/5 "2019-06-04T19:12:33Z")

</div>

That is correct – but it’d still be nice to have `tempdir()` behave consistently regarding the trailing slash.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 5, 2019, 5:50am UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930/6 "2019-06-05T05:50:34Z")

</div>

I am not sure why it would matter. You cannot consistently rely on the presence of trailing `/`s in most contexts, and as others have pointed out, should always use the relevant API for working with paths, instead of treating them as strings.

Incidentally, perhaps it would be useful to experiment with a specific type for paths (in a package), possibly wrapping a string but in an opaque way. Beside trivial puns (eg `*` could be `joinpath`, `abs` would make absolute paths), it would enforce the API more idiomatically.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 5, 2019, 6:49am UTC](https://discourse.julialang.org/t/tempdir-differences-in-windows-and-linux/24930/7 "2019-06-05T06:49:23Z")

</div>

> [@Tamas\_Papp](#):
>
> Incidentally, perhaps it would be useful to experiment with a specific type for paths (in a package), possibly wrapping a string but in an opaque way. Beside trivial puns (eg `*` could be `joinpath` , `abs` would make absolute paths), it would enforce the API more idiomatically.

See [GitHub - rofinn/FilePaths.jl: A type based approach to working with filesystem paths in julia](https://github.com/rofinn/FilePaths.jl) and [https://github.com/JuliaLang/Juleps/pull/26](https://github.com/JuliaLang/Juleps/pull/26)
