Skip to contents

This function extracts the file extension from a given file path. It first checks if the input is not NULL and is a character string. If these conditions are met, it then uses the tools::file_ext function to extract and return the file extension. The function does not check the existence of the file or explicitly get the file type from its content. It merely guess file extension from the file name.

Usage

FileExt(Path)

Arguments

Path

A character string representing the file path from which the file extension is to be extracted. It must not be NULL and has to be a character string.

Value

A character string representing the file extension of the given file path. If the path does not have an extension, an empty string is returned.

See also

Author

Ahmed El-Gabbas

Examples

FileExt(Path = "File.doc")
#> [1] "doc"

FileExt(Path = "D:/File.doc")
#> [1] "doc"

FileExt(Path = "File.1.doc")
#> [1] "doc"

FileExt(Path = "D:/Files.All")
#> [1] "All"

FileExt(Path = "D:/Files.All/")
#> [1] ""

FileExt("example.txt") # Returns "txt"
#> [1] "txt"

FileExt("archive.tar.gz") # Returns "gz"
#> [1] "gz"