Learn R Programming

evanverse (version 0.3.7)

get_ext: get_ext: Extract File Extension(s)

Description

Extract file extension(s) from a file name or path. Supports vector input and optionally preserves compound extensions (e.g., .tar.gz) when keep_all = TRUE.

Usage

get_ext(paths, keep_all = FALSE, include_dot = FALSE, to_lower = FALSE)

Value

Character vector of extensions.

Arguments

paths

Character vector of file names or paths.

keep_all

Logical. If TRUE, returns full suffix after first dot in basename. If FALSE, returns only the last extension. Default is FALSE.

include_dot

Logical. If TRUE, includes the leading dot in result. Default is FALSE.

to_lower

Logical. If TRUE, converts extensions to lowercase. Default is FALSE.

Examples

Run this code
get_ext("data.csv")               # "csv"
get_ext("archive.tar.gz")         # "gz"
get_ext("archive.tar.gz", TRUE)   # "tar.gz"
get_ext(c("a.R", "b.txt", "c"))   # "R" "txt" ""
get_ext("data.CSV", to_lower = TRUE)  # "csv"

Run the code above in your browser using DataLab