Get File Extension

From CodeCodex

Implementations[edit]

Erlang[edit]

file_extension(Path) ->
    filename:extension(Path).

Haskell[edit]

import System.FilePath.Posix ( takeExtension )
fileExtension = takeExtension

Perl[edit]

use File::Basename;

sub file_extension {
	my $path = shift;

	return ( fileparse($path, qr/\.[^.]*/) )[2];
}

PHP[edit]

function file_extension($filename)
{
    return pathinfo($filename, PATHINFO_EXTENSION);
}

Python[edit]

import os.path

def file_extension(path):
    return os.path.splitext(path)[1]

Ruby[edit]

def file_extension(path)
  File.extname(path)
end

Tcl[edit]

proc file_extension path {return [file extension $path]}