dir_ls() is equivalent to the ls command. It returns filenames as a fs_path character vector. 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, recursive = FALSE, type = "any",
  glob = NULL, regexp = NULL, invert = FALSE, ...)

dir_map(path = ".", fun, all = FALSE, recursive = FALSE, type = "any")

dir_walk(path = ".", fun, all = FALSE, recursive = FALSE, type = "any")

dir_info(path = ".", all = FALSE, recursive = FALSE, type = "any",
  regexp = NULL, glob = NULL, ...)

Arguments

path

A character vector of one or more paths.

all

If TRUE hidden files are also returned.

recursive

Should directories be listed recursively? the filenames.

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

...

Additional arguments passed to grep.

fun

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

Examples

dir_ls(R.home("share"), type = "directory")
#> /Library/Frameworks/R.framework/Resources/share/R #> /Library/Frameworks/R.framework/Resources/share/Rd #> /Library/Frameworks/R.framework/Resources/share/dictionaries #> /Library/Frameworks/R.framework/Resources/share/encodings #> /Library/Frameworks/R.framework/Resources/share/java #> /Library/Frameworks/R.framework/Resources/share/licenses #> /Library/Frameworks/R.framework/Resources/share/make #> /Library/Frameworks/R.framework/Resources/share/sh #> /Library/Frameworks/R.framework/Resources/share/texmf #> /Library/Frameworks/R.framework/Resources/share/zoneinfo
# Create a shorter link link_create(system.file(package = "base"), "base") dir_ls("base", recursive = 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 #> <fs::path> <fct> <fs::by> <fs::perms> <dttm> <chr> <chr> #> 1 base/CITATION file 956 rw-rw-r-- 2017-12-06 21:16:12 root admin #> 2 base/DESCRIPTION file 286 rw-rw-r-- 2017-12-06 21:16:12 root admin #> 3 base/INDEX file 23.2K rw-rw-r-- 2017-12-06 21:16:12 root admin #> 4 base/Meta direct… 272 rwxrwxr-x 2017-12-06 21:16:12 root admin #> 5 base/R direct… 204 rwxrwxr-x 2017-12-06 21:16:12 root admin #> 6 base/demo direct… 204 rwxrwxr-x 2017-12-06 21:16:12 root admin #> 7 base/help direct… 238 rwxrwxr-x 2017-12-06 21:16:12 root admin #> 8 base/html direct… 136 rwxrwxr-x 2017-12-06 21:16:12 root admin #> # ... with 11 more variables: device_id <dbl>, 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")