R: List files

dir_ls {fs} | R Documentation

## List files

### Description

`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`.

### Usage

    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")

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

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

    dir_map("base", identity)

    dir_walk("base", str)

    dir_info("base")

    # Cleanup
    link_delete("base")

[Package fs version 1.3.2 Index]