# Using relative path names . and

**URL:** <https://discourse.julialang.org/t/using-relative-path-names-and/63262>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 20, 2021, 9:47pm UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262 "2021-06-20T21:47:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmv/32/26323_2.png) [@mmv](https://discourse.julialang.org/u/mmv)\
**Post date:** [June 20, 2021, 9:47pm UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262/1 "2021-06-20T21:47:43Z")

</div>

Hi! I m trying to list the regular files in the current or parent directory, to the exclusion of directories and subdirectories, using the relative paths “.” and “…”, with mixed results:

```julia
julia> pwd()
"/Users/michel/Codes/Julia/parent/child"

shell> ls
c_file1 c_file2

shell> ls ..
child p_file

julia> filter(x -> isfile(x), readdir("."))
2-element Vector{String}:
 "c_file1"
 "c_file2"

julia> filter(x -> isfile(x), readdir(".."))
String[]

```

Why is this command working as expected with “.” but not returning the name of the file (p\_file) in the parent directory “…”? Thanks for any clarification.

---

<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:** [June 21, 2021, 8:51am UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262/2 "2021-06-21T08:51:36Z")

</div>

Because `isfile` is provided the filename of a file which is not in the current directory.

When you use `readdir("..",join=true)` it should work as the full path is passed to `isfile`.

---

<div class="post-metadata">

**Author:** ![mmv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmv/32/26323_2.png) [@mmv](https://discourse.julialang.org/u/mmv)\
**Post date:** [June 21, 2021, 9:25am UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262/3 "2021-06-21T09:25:24Z")

</div>

@feanor12: Thanks for answering. Indeed:

```julia
julia> filter(x -> isfile(x), readdir(".."))
String[]

julia> filter(x -> isfile(x), readdir("..", join = true))
1-element Vector{String}:
 "../p_file"

```

and also

```julia
julia> filter(x -> isfile("../" * x), readdir(".."))
1-element Vector{String}:
 "p_file"

```

---

<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:** [June 21, 2021, 9:28am UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262/4 "2021-06-21T09:28:13Z")

</div>

Or put another way,

```julia
filter(x -> isfile(x), readdir(d))

```

will only do what you expect if `d` is effectively the same as your current directory, e.g. `"."` or the absolute path to your current directory.

What you should do instead is either

```julia
filter(x -> isfile(joinpath(d, x)), readdir(d))

```

or

```julia
filter(x -> isfile(x), readdir(d, join = true))

```

depending on whether you want full paths in the result for further processing.

---

<div class="post-metadata">

**Author:** ![mmv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmv/32/26323_2.png) [@mmv](https://discourse.julialang.org/u/mmv)\
**Post date:** [June 21, 2021, 9:30am UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262/5 "2021-06-21T09:30:13Z")

</div>

@GunnarFarneback: Great! Even better. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [June 21, 2021, 11:29am UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262/6 "2021-06-21T11:29:12Z")

</div>

Note that

```julia
filter(x -> isfile(x), readdir(d, join = true))

```

can be simplified to

```julia
filter(isfile, readdir(d, join = true))

```

---

<div class="post-metadata">

**Author:** ![mmv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmv/32/26323_2.png) [@mmv](https://discourse.julialang.org/u/mmv)\
**Post date:** [June 21, 2021, 3:06pm UTC](https://discourse.julialang.org/t/using-relative-path-names-and/63262/7 "2021-06-21T15:06:17Z")

</div>

@sijo: Very interesting. I did not know this was even allowed… This being said, I’m also working on a Mac, which creates “hidden files” that I want to filter out too, like this:

```julia
filter(x -> isfile(joinpath(fpath, x)) && x != ".DS_Store", readdir(fpath, join = false)))

```

so I guess in need to keep the `x` notation in order to use it in the subsequent test… unless there is another trick to be learned!

Thanks for your input.
