Learn R Programming

Smisc (version 0.3.9.1)

getExtension: Get the extension of a vector of filenames

Description

Get the extension of a vector of filenames, assuming that the extension is the set of characters that follows the last ".". A wrapper for grabLast.

Usage

getExtension(vec, split.char = ".")

Arguments

vec

Character vector (usually containing filenames)

split.char

A single character used to split the character strings

Value

Character vector of filename extensions

Details

Assumes paths are delineated using forward slashes. If an NA is supplied, then an NA is returned. If the desired string doesn't exist (see examples below), a "" is returned.

See Also

Additional functions for filename manipulations: stripExtension, stripPath, getPath, grabLast, basename, dirname

Examples

Run this code
# NOT RUN {
getExtension(c(a = "this old file.doc",
               b = "that young file.rtf",
               c = "this.good.file.doc",
               d = "this_bad_file",
               e = "thisfile.",
               f = NA,
               g = "that.this.pdf",
               h = ".", i = ""))

# An example with 'real' files
files <- dir(file.path(path.package(package = "Smisc"), "data"), full.names = TRUE)
print(files)
getExtension(files)
# }

Run the code above in your browser using DataLab