fs (version 1.2.6)

dir_ls: List files

Description

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.

Usage

dir_ls(path = ".", all = FALSE, recursive = FALSE, type = "any",
  glob = NULL, regexp = NULL, invert = FALSE, fail = TRUE, ...)

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

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

dir_info(path = ".", all = FALSE, recursive = 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.

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

fail

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

...

Additional arguments passed to grep.

fun

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

Examples

Run this code
# NOT RUN {
dir_ls(R.home("share"), type = "directory")

# Create a shorter link
link_create(system.file(package = "base"), "base")

dir_ls("base", recursive = TRUE, glob = "*.R")

dir_map("base", identity)

dir_walk("base", str)

dir_info("base")

# Cleanup
link_delete("base")
# }

Run the code above in your browser using DataCamp Workspace