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, ...)

Arguments

path

A character vector of one or more paths.

all

If TRUE hidden files are also returned.

recurse

If TRUE recurse fully, if a positive number the number of levels to recurse.

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. *.csv) passed on to grep() to filter paths.

regexp

A regular expression (e.g. [.]csv$) passed on to grep() to filter paths.

invert

If TRUE return files which do not match

fail

Should the call fail (the default) or warn if a file cannot be accessed.

...

Additional arguments passed to grep.

recursive

(Deprecated) If TRUE recurse fully.

fun

A function, taking one parameter, the current path entry.

Examples

dir_ls(R.home("share"), type = "directory")
#> /home/travis/R-bin/lib/R/share/R #> /home/travis/R-bin/lib/R/share/Rd #> /home/travis/R-bin/lib/R/share/dictionaries #> /home/travis/R-bin/lib/R/share/encodings #> /home/travis/R-bin/lib/R/share/java #> /home/travis/R-bin/lib/R/share/licenses #> /home/travis/R-bin/lib/R/share/make #> /home/travis/R-bin/lib/R/share/sh #> /home/travis/R-bin/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.R
dir_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")
#> # A tibble: 8 x 18 #> path type size permissions modification_time user group device_id #> <fs::path> <fct> <fs::> <fs::perms> <dttm> <chr> <chr> <dbl> #> 1 base/CITA… file 956 rw-r--r-- 2019-04-29 14:22:44 trav… trav… 2049 #> 2 base/DESC… file 286 rw-r--r-- 2019-04-29 14:22:44 trav… trav… 2049 #> 3 base/INDEX file 23.4K rw-rw-r-- 2019-04-29 14:22:44 trav… trav… 2049 #> 4 base/Meta dire… 4K rwxrwxr-x 2019-04-29 14:22:44 trav… trav… 2049 #> 5 base/R dire… 4K rwxrwxr-x 2019-04-29 14:22:44 trav… trav… 2049 #> 6 base/demo dire… 4K rwxrwxr-x 2019-04-29 14:22:44 trav… trav… 2049 #> 7 base/help dire… 4K rwxrwxr-x 2019-04-29 14:22:44 trav… trav… 2049 #> 8 base/html dire… 4K rwxrwxr-x 2019-04-29 14:22:44 trav… trav… 2049 #> # … with 10 more variables: hard_links <dbl>, special_device_id <dbl>, #> # inode <dbl>, block_size <dbl>, blocks <dbl>, flags <int>, generation <dbl>, #> # access_time <dttm>, change_time <dttm>, birth_time <dttm>
# Cleanup link_delete("base")