Extract File Extension

file_extension(x, ext = NULL)

Arguments

x

path as a character vector.

ext

extension to append instead of the original extension.

Examples

file_extension('alpha.txt')
#> [1] "txt"
file_extension(paste('aa.tt', 1:5, sep=''))
#> [1] "tt1" "tt2" "tt3" "tt4" "tt5"
# change extension file_extension(paste('aa.tt', 1:5, sep=''), 'pdf')
#> [1] "aa.pdf" "aa.pdf" "aa.pdf" "aa.pdf" "aa.pdf"
file_extension(paste('aatt', 1:5, sep=''), 'pdf')
#> [1] "aatt1.pdf" "aatt2.pdf" "aatt3.pdf" "aatt4.pdf" "aatt5.pdf"