dir_ls() is equivalent to the ls command. It returns filenames as a
named fs_path character vector. The names are equivalent to the values,
which is useful for passing onto functions like purrr::map_dfr().
dir_info() is equivalent to ls -l and a shortcut for
file_info(dir_ls()).
dir_map() applies a function fun() to each entry in the path and returns
the result in a list.
dir_walk() calls fun for its side-effect and returns the input path.
dir_ls( path = ".", all = FALSE, recurse = FALSE, type = "any", glob = NULL, regexp = NULL, invert = FALSE, fail = TRUE, ..., recursive ) dir_map( path = ".", fun, all = FALSE, recurse = FALSE, type = "any", fail = TRUE ) dir_walk( path = ".", fun, all = FALSE, recurse = FALSE, type = "any", fail = TRUE ) dir_info( path = ".", all = FALSE, recurse = FALSE, type = "any", regexp = NULL, glob = NULL, fail = TRUE, ... )
| path | A character vector of one or more paths. |
|---|---|
| all | If |
| recurse | If |
| type | File type(s) to return, one or more of "any", "file", "directory", "symlink", "FIFO", "socket", "character_device" or "block_device". |
| glob | A wildcard aka globbing pattern (e.g. |
| regexp | A regular expression (e.g. |
| invert | If |
| fail | Should the call fail (the default) or warn if a file cannot be accessed. |
| ... | Additional arguments passed to grep. |
| recursive | (Deprecated) If |
| fun | A function, taking one parameter, the current path entry. |
#> /opt/R/3.6.2/lib/R/share/R /opt/R/3.6.2/lib/R/share/Rd #> /opt/R/3.6.2/lib/R/share/dictionaries /opt/R/3.6.2/lib/R/share/encodings #> /opt/R/3.6.2/lib/R/share/java /opt/R/3.6.2/lib/R/share/licenses #> /opt/R/3.6.2/lib/R/share/make /opt/R/3.6.2/lib/R/share/sh #> /opt/R/3.6.2/lib/R/share/texmf# Create a shorter link link_create(system.file(package = "base"), "base") dir_ls("base", recurse = TRUE, glob = "*.R")#> base/demo/error.catching.R base/demo/is.things.R #> base/demo/recursion.R base/demo/scoping.Rdir_map("base", identity)#> [[1]] #> [1] "base/CITATION" #> #> [[2]] #> [1] "base/DESCRIPTION" #> #> [[3]] #> [1] "base/INDEX" #> #> [[4]] #> [1] "base/Meta" #> #> [[5]] #> [1] "base/R" #> #> [[6]] #> [1] "base/demo" #> #> [[7]] #> [1] "base/help" #> #> [[8]] #> [1] "base/html" #>dir_walk("base", str)#> chr "base/CITATION" #> chr "base/DESCRIPTION" #> chr "base/INDEX" #> chr "base/Meta" #> chr "base/R" #> chr "base/demo" #> chr "base/help" #> chr "base/html"dir_info("base")#> path type size permissions modification_time user group #> 1 base/CITATION file 956 rw-r--r-- 2020-01-09 12:34:14 root root #> 2 base/DESCRIPTION file 286 rw-r--r-- 2020-01-09 12:34:14 root root #> 3 base/INDEX file 23.41K rw-r--r-- 2020-01-09 12:34:14 root root #> 4 base/Meta directory 4K rwxr-xr-x 2020-01-09 12:34:14 root root #> 5 base/R directory 4K rwxr-xr-x 2020-01-09 12:34:15 root root #> 6 base/demo directory 4K rwxr-xr-x 2020-01-09 12:34:14 root root #> 7 base/help directory 4K rwxr-xr-x 2020-01-09 12:34:14 root root #> 8 base/html directory 4K rwxr-xr-x 2020-01-09 12:34:14 root root #> device_id hard_links special_device_id inode block_size blocks flags #> 1 66305 1 0 5409632 4096 8 0 #> 2 66305 1 0 5409626 4096 8 0 #> 3 66305 1 0 5409633 4096 48 0 #> 4 66305 2 0 5409634 4096 8 0 #> 5 66305 2 0 5409621 4096 8 0 #> 6 66305 2 0 5409627 4096 8 0 #> 7 66305 2 0 5409641 4096 8 0 #> 8 66305 2 0 5409647 4096 8 0 #> generation access_time change_time birth_time #> 1 0 2020-01-09 12:34:14 2020-01-09 12:34:14 2020-01-09 12:34:14 #> 2 0 2020-04-23 13:10:05 2020-01-09 12:34:14 2020-01-09 12:34:14 #> 3 0 2020-01-09 12:34:14 2020-01-09 12:34:14 2020-01-09 12:34:14 #> 4 0 2020-04-23 06:25:10 2020-01-09 12:34:14 2020-01-09 12:34:14 #> 5 0 2020-04-23 06:25:10 2020-01-09 12:34:15 2020-01-09 12:34:15 #> 6 0 2020-04-23 06:25:10 2020-01-09 12:34:14 2020-01-09 12:34:14 #> 7 0 2020-04-23 06:25:10 2020-01-09 12:34:14 2020-01-09 12:34:14 #> 8 0 2020-04-23 06:25:10 2020-01-09 12:34:14 2020-01-09 12:34:14