fs icon indicating copy to clipboard operation
fs copied to clipboard

Improve glob interface for `dir_ls()`

Open jimhester opened this issue 6 years ago • 5 comments

This should work more like the command line

e.g. this should work

fs::dir_ls(glob = "/path/to/file*ext")

now you need to use something like

fs::dir_ls("/path/to", glob = "*file*ext")

Sys.glob("/path/to/file*ext") does work in this way.

jimhester avatar Feb 09 '19 16:02 jimhester

Hi,

this would be a great functionality! On the other hand, will it be like Sys.glob that you can put a regular expression in any part oh the path? I mean, in Sys.glob you can do this: Sys.glob("/path/subpath1/*/subpath2/file*ext") but I am not sure if in dir_ls you'll do: fs::dir_ls(glob = "/path/subpath1/*/subpath2/file*ext")

Many thanks

ralonso-igenomix avatar Feb 12 '19 07:02 ralonso-igenomix

Not sure if this is known/intended, but: fs::dir_ls("/path/to", glob = "*file*ext") is not identical to Sys.glob("/path/to/file*ext"), as the first will find any file containing "file" (e.g. tmpfile_01.ext, file_02.ext, file.ext, ...) while the latter will find only those beginning with "file".

And following this: At the moment fs::dir_ls("/path/to", glob = "file*") is not working. It seems, that the glob argument needs to start with a wildcard to work properly. Not sure if this qualifies as an independent issue...

Best Jonas

grszkthfr avatar Oct 31 '19 12:10 grszkthfr

Dear,

any update on this?

Best,

Roberto

ralonso-igenomix avatar May 03 '22 16:05 ralonso-igenomix

Hi, How can we use a variable in glob= parameter? It did not work with the below example: group <- "vet_REF_pas" glob = get(paste0("msmc.",group,"_out_non_empty.20bootstrap_chr*.final.txt"))

Error in get(paste0("msmc.", group, "_out_non_empty.20bootstrap_chr*.final.txt")) : 
  object 'msmc.vet_REF_pas_out_non_empty.20bootstrap_chr*.final.txt' not found

Best, Liu

yzliu01 avatar May 06 '24 14:05 yzliu01

@yzliu01 You don't need the get(), just the paste0().

gaborcsardi avatar May 06 '24 19:05 gaborcsardi