image

the sleepy snake

index :: path :: get_ext

get_ext(path, components=1)

Returns the file extension part of a path or empty string

The components keyword can be used to handle filenames containing multiple extensions. See the table below:

value effect
1 Default. Extension is the last component separated by a dot (myfile.ext)
1 Extension is any number of components up to the number specified (myfile.ext1.ext(N))
1 Extension is any number of dot separated components (myfile.ext1.ext2.ext(...))
fpath = "myfile.txt.zip"

get_ext(fpath)
>> ".zip"

get_ext(fpath, -1)
>> ".txt.zip"