# Why is expanduser not used in abspath

**URL:** <https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136>\
**Category:** Internals & Design\
**Tags:** filesystem\
**Created:** [March 19, 2022, 4:28pm UTC](https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136 "2022-03-19T16:28:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [March 19, 2022, 4:28pm UTC](https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136/1 "2022-03-19T16:28:54Z")

</div>

I noticed that the tilde symbol is not handled by abspath. What function should I use to expand a path shorthand?

```julia
julia> expanduser("~/.julia")
"/home/michael/.julia"

julia> abspath("~/.julia")
"/home/michael/~/.julia"

```

A quick workaround would be :

```julia
julia> fullpath = abspath∘expanduser
abspath ∘ expanduser

julia> fullpath("~/.julia")
"/home/michael/.julia"

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 19, 2022, 4:58pm UTC](https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136/2 "2022-03-19T16:58:47Z")

</div>

> Why is expanduser not used in abspath

`~` is a valid directory name.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 19, 2022, 6:04pm UTC](https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136/3 "2022-03-19T18:04:50Z")

</div>

I need to question from where the `~` comes. If it comes from string literals inside the code, then ok. But if you are doing this to strings that come from the user you can make impossible to refer to a folder/file called `~`.

---

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [March 19, 2022, 7:14pm UTC](https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136/4 "2022-03-19T19:14:54Z")

</div>

That makes it quite tricky then. 🤔

The problem I had was something like this.

```julia
julia> dir = "~/.julia"
"~/.julia"

julia> isdir(dir)
false

julia> isdir(expanduser(dir))
true

julia> isdir(abspath(dir))
false

```

---

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [March 19, 2022, 7:21pm UTC](https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136/5 "2022-03-19T19:21:08Z")

</div>

Maybe something like this would work

```julia
function fullpath(path)
  if ispath(path)
    abspath(path)
  else 
    alt_path = expanduser(path)
    ispath(alt_path) ? alt_path : abspath(path)
  end
end

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 19, 2022, 7:25pm UTC](https://discourse.julialang.org/t/why-is-expanduser-not-used-in-abspath/78136/6 "2022-03-19T19:25:11Z")

</div>

`abspath` uses [`isabspath`](https://docs.julialang.org/en/v1/base/file/#Base.Filesystem.isabspath) to check whether a path is already absolute, which simply checks whether the path starts with `/`, it doesn’t do any checks about the existence of the path on disk. A path starting with `~/...` is a legitimate non-absolute path.
