r-lib / fs

Provide cross platform file operations based on libuv.
https://fs.r-lib.org/
Other
364 stars 80 forks source link

`dir_tree()` not listing files inside a directory inside `path` when glob or regexp is used #398

Open dhersz opened 1 year ago

dhersz commented 1 year ago

Hi. I'm having a issue where I'm trying to list some zip files inside a directory in my project using dir_tree() and they're not showing up. I thought I was messing up with glob or regexp, but it doesn't seem to be the case, since dir_ls() works fine. Example below:

library(fs)

dir_path <- tempfile("tmpdir")
dir.create(dir_path)

nested_dir <- file.path(dir_path, "nested_dir")
dir.create(nested_dir)

dir_tree(dir_path)
#> /tmp/RtmpCR1OTJ/tmpdir8bdf67c149e7
#> └── nested_dir

file.create(file.path(nested_dir, "a.zip"))
#> [1] TRUE
file.create(file.path(nested_dir, "b.zip"))
#> [1] TRUE

dir_tree(dir_path, recurse = TRUE, glob = "*.zip")
#> /tmp/RtmpCR1OTJ/tmpdir8bdf67c149e7

dir_ls(dir_path, recurse = TRUE, glob = "*.zip")
#> /tmp/RtmpCR1OTJ/tmpdir8bdf67c149e7/nested_dir/a.zip
#> /tmp/RtmpCR1OTJ/tmpdir8bdf67c149e7/nested_dir/b.zip

dir_tree(dir_path)
#> /tmp/RtmpCR1OTJ/tmpdir8bdf67c149e7
#> └── nested_dir
#>     ├── a.zip
#>     └── b.zip

You can see that both a.zip and b.zip are listed using dir_ls(), but this is not the case when using dir_tree(). I'd hope that the output of the first dir_tree() attempt would look like the second one, but that's not the case. I tried many different patterns ("nested_dir/a.zip", "*/*.zip", ...), but none seemed to work.

Not sure if this is intended behaviour or not, but I'd imagine that both dir_tree() and dir_ls() would output the same file list. Cheers!

olivroy commented 1 year ago

I have the same issue!