Learn R Programming

ribiosUtils (version 1.5-6)

extname: Get the base and extension(s) of file name(s)

Description

Many files have base and extensions in their names, for instance for the file mybook.pdf, the base is mybook and the extension is pdf. basefilename extname functions extract these information from one or more file names.

Usage

extname(x, ifnotfound = NA, lower.case = FALSE)

Arguments

x

Character vector of file names; other classes will be coereced to characters

ifnotfound

If no extension name was found, the value to be returned. Default is NA

lower.case

Logical, should the names returned in lower case?

Value

The base file name or the extension as characters, of the same length as the input file name character. In case that a file name does not contain a extension, NA will be returned.

Examples

Run this code
# NOT RUN {
extname("mybook.pdf")
extname("sequence.in.fasta")
extname(c("/path/mybook.pdf", "test.doc"))
extname("README")
extname("README", ifnotfound="")
extname("/path/my\ home/Holiday Plan.txt")

basefilename("mybook.pdf")
basefilename("sequence.in.fasta")
basefilename(c("/path/mybook.pdf", "test.doc"))
basefilename("README")
basefilename("/path/my\ home/Holiday Plan.txt")

basefilename("myBook.pdf", lower.case=TRUE)
extname("myBook.PDF", lower.case=TRUE)

# }

Run the code above in your browser using DataLab