Skip to contents

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)

Arguments

paths

A character vector of file names or paths.

keep_all

Logical. If TRUE, returns full suffix after first dot in basename (e.g., "tar.gz"); otherwise returns only the last extension. Default: FALSE.

Value

A character vector of extensions (no leading dots).

Examples

get_ext("data.csv")               # "csv"
#> [1] "csv"
get_ext("archive.tar.gz")        # "gz"
#> [1] "gz"
get_ext("archive.tar.gz", TRUE)  # "tar.gz"
#> [1] "tar.gz"
get_ext(c("a.R", "b.txt", "c"))   # "R" "txt" ""
#> [1] "R"   "txt" ""