manage_files: Manage File Operations

View source: R/manage_files.R

manage_filesR Documentation

Manage File Operations

Description

Perform file operations such as listing, copying, and moving files based on file name prefixes, suffixes, or any part of the file name. It handles files in the working directory and can operate on them based on the given action parameter.

Usage

manage_files(
  action = "list",
  prefix = "",
  suffix = "",
  match_any = "",
  target_directory = NULL
)

Arguments

action

A string specifying the operation to perform on the files: 'list' to display file names, 'copy' to copy files, or 'move' to move files. Default is 'list'.

prefix

A string indicating the prefix of the file names to match. Default is an empty string, which means no prefix filtering.

suffix

A string indicating the suffix of the file names to match. Default is an empty string, which means no suffix filtering.

match_any

A string that should appear anywhere in the file name. Default is an empty string, which means no general text filtering.

target_directory

A string indicating the directory where files should be copied or moved. It must be a valid path or NULL if only listing files. Default is NULL.

Value

Invisible TRUE if the operation was successful, FALSE otherwise. If 'list' action is selected, it prints the list of matched files.

Examples

# List all files containing "report" in their names
manage_files(action = "list", match_any = "report")

# Copy all files starting with "data_" and ending with "_2023.txt" to the "archive/" directory
manage_files(action = "copy", prefix = "data_", suffix = "_2023.txt", target_directory = "archive/")

# Move all files ending with "_result.txt" to the parent directory
manage_files(action = "move", suffix = "_result.txt", target_directory = "../")


pygmyperch/melfuR documentation built on Aug. 26, 2024, 12:48 a.m.