Extract file extension from file path

SFun28 picture SFun28 · Oct 15, 2011 · Viewed 32.2k times · Source

How can I extract the extension of a file given a file path as a character? I know I can do this via regular expression regexpr("\\.([[:alnum:]]+)$", x), but wondering if there's a built-in function to deal with this?

Answer

Carl Witthoft picture Carl Witthoft · Oct 15, 2011

This is the sort of thing that easily found with R basic tools. E.g.: ??path.

Anyway, load the tools package and read ?file_ext .