Very simple but often applicable function to retrieve or change the file name extension (from say file.lst to file.mod)

fnExtension(fn, ext)

Arguments

fn

file name. Often ending in an extension after a period but the extension is not needed.

ext

new file name extension. If omitted or NULL, the extension of fn is returned.

Value

A text string

Examples

fnExtension("file.lst",".mod")
#> [1] "file.mod"
fnExtension("file.lst","mod")
#> [1] "file.mod"
fnExtension("file.lst","..mod")
#> [1] "file..mod"
fnExtension("file.lst",cc(.mod,xml))
#> [1] "file.mod" "file.xml"
fnExtension(cc(file1.lst,file2.lst),cc(.xml))
#> [1] "file1.xml" "file2.xml"
fnExtension(cc(file1.lst,file2.lst),cc(.xml,.cov))
#> [1] "file1.xml" "file2.cov"
fnExtension("file.lst","")
#> [1] "file"
fnExtension("file.lst")
#> [1] "lst"