listFiles: Enhanced File Listing with Support for Wildcard Patterns

View source: R/utilsFiles.R

listFilesR Documentation

Enhanced File Listing with Support for Wildcard Patterns

Description

This function is a wrapper around list.files from base R, providing additional options such as automatic conversion from glob to regex patterns, this function supports direct use of standard directory patterns like "*" and "?" for matching files. Full names is enabled automatically when recursive search is activated.

Usage

listFiles(
  path = ".",
  pattern = "*",
  fullnames = FALSE,
  recursive = FALSE,
  regex = FALSE
)

Arguments

path

Character. The path where to look for the files. Defaults to the current directory.

pattern

Character. The pattern to match the files against. Supports both glob and regex patterns. Defaults to "*".

fullnames

Logical. Whether to return full names including the path. Defaults to FALSE.

recursive

Logical. Whether to list files recursively. Defaults to FALSE.

regex

Logical. Whether the provided pattern is a regex pattern. Defaults to FALSE.

Value

Character vector. A vector of file names that match the criteria.

Examples

## Not run: 
listFiles(path = "path/to/directory", pattern = "*.txt")
listFiles(path = "path/to/directory", pattern = "file[0-9]\\.txt", regex = TRUE)

## End(Not run)

Epiconcept-Paris/STRAP-epiuf documentation built on Aug. 5, 2024, 3:41 a.m.