get_file_ext function

Extract File Extension

Extract File Extension

Extract the extension of a file.

get_file_ext(x, compression = TRUE)

Arguments

  • x: 'character' vector. File path(s).
  • compression: 'logical' flag. Whether to account for the compression extension '.gz', '.bz2' or '.xz'.

Returns

Returns the file (name) extensions (excluding the leading dot).

Examples

c("dir/file.txt", "file.txt.gz") |> get_file_ext()

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center