Scan a filename for it's extension.

    :param filename: string of the filename
    :return: the extension off the end (empty string if it can't find one)
339577
def ext_from_filename(filename):
    
    try:
        base, ext = filename.lower().rsplit(".", 1)
    except ValueError:
        return ''
    ext = ".{0}".format(ext)
    all_exts = [x.extension for x in chain(magic_header_array,
                                           magic_footer_array)]

    if base[-4:].startswith("."):
        # For double extensions like like .tar.gz
        long_ext = base[-4:] + ext
        if long_ext in all_exts:
            return long_ext
    return ext
149783
public static String getExtension(String fileName) {
        int dotIndex = fileName.lastIndexOf(DOT);
        return dotIndex > 0 ? fileName.substring(dotIndex) : EMPTY;
    }
1154735
def type(filename):
    
    assert isinstance(filename, basestring)
    while 1:
        filename, suffix = os.path.splitext (filename)
        if not suffix: return None
        suffix = suffix[1:]

        if suffix in __suffixes_to_types:
            return __suffixes_to_types[suffix]
713767
def split_extension(pathname):
        
        filepart = win32.PathRemoveExtension(pathname)
        extpart  = win32.PathFindExtension(pathname)
        return (filepart, extpart)
1272670
private static String getExtension(String fileName) {
        // play it safe and get rid of any fragment id
        // that might be there
        int length = fileName.length();

        int newEnd = fileName.lastIndexOf('#');
        if (newEnd == -1) {
            newEnd = length;
        }
        int i = fileName.lastIndexOf('.', newEnd);
        if (i != -1) {
            return fileName.substring(i + 1, newEnd);
        } else {
            // no extension, no content type
            return null;
        }
    }
306969
public static function getFileExtension($filename)
    {
        $filename = basename($filename);

        // remove possible query string
        $pos = strpos($filename, '?');
        if ($pos !== false) {
            $filename = substr($filename, 0, $pos);
        }

        // retrieve the extension
        $pos = strrpos($filename, '.');
        if ($pos !== false) {
            return strtolower(substr($filename, $pos + 1));
        }

        return '';
    }
1320585
public static String getExtension(String fileName) {
		if (fileName==null){
			return null;
		} else {
			int number=fileName.lastIndexOf('.');
			
			if (number>=0){
				return fileName.substring(number+1, fileName.length());
			} else {
				return null;
			}
		}		
	}
412326
def list_files(dirname, extension=None):
    
    f = []
    for (dirpath, dirnames, filenames) in os.walk(dirname):
        f.extend(filenames)
        break
    if extension is not None:
        # Filter on extension
        filtered = []
        for filename in f:
            fn, ext = os.path.splitext(filename)
            if ext.lower() == '.' + extension.lower():
                filtered.append(filename)
        f = filtered
    return f
315136
public static String getFileNameWithoutExtenxion(String fileName) {
		if (fileName==null){
			return null;
		} else {
			int number=fileName.lastIndexOf('.');
			
			if (number>=0){
				return fileName.substring(0, number);
			} else {
				return fileName;
			}
		}		
	}
1016398
protected static String getExtension(String scriptName)
    {
        if (scriptName == null)
        {
            return null;
        }

        int filePosition = scriptName.lastIndexOf("/");
        String fileName;

        if (scriptName.lastIndexOf("\\") > filePosition)
        {
            filePosition = scriptName.lastIndexOf("\\");
        }

        if (filePosition >= 0)
        {
            fileName = scriptName.substring(filePosition + 1);
        }
        else
        {
            fileName = scriptName;
        }

        final int extensionPosition = fileName.lastIndexOf(".");
        if (extensionPosition >= 0)
        {
            return fileName.substring(extensionPosition + 1);
        }

        return null;
    }
558751
private static String getFileExtension(final String filename) {

		String extension = "";
		int i = filename.lastIndexOf('.');
		int p = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
		if (i > p)
			extension = filename.substring(i+1);

		return extension;
	}
235524
def format_from_extension(fname):
    
    _base, ext = os.path.splitext(fname)
    if not ext:
        return None
    try:
        format = known_extensions[ext.replace('.', '')]
    except KeyError:
        format = None
    return format
263700
def getExistingFile(name, max_suffix=1000):
    
    num = 1
    stem, ext = os.path.splitext(name)
    filename = name
    while not os.path.exists(filename):
        suffix = "-%d" % num
        filename = stem + suffix + ext
        num += 1
        if num >= max_suffix:
            raise ValueError("No file %r found" % name)
    return filename
657558
def _read_file(self, filename):
        

        if self.__compression:
            f = gzip.GzipFile(filename, "rb")
        else:
            f = open(filename, "rb")
        res = pickle.load(f)
        f.close()
        return res
1356383
def parseFilename(filename):
    
    # Parse out any extension specified in filename
    _indx = filename.find('[')
    if _indx > 0:
        # Read extension name provided
        _fname = filename[:_indx]
        extn = filename[_indx+1:-1]

        # An extension was provided, so parse it out...
        if repr(extn).find(',') > 1:
            _extns = extn.split(',')
            # Two values given for extension:
            #    for example, 'sci,1' or 'dq,1'
            _extn = [_extns[0],int(_extns[1])]
        elif repr(extn).find('/') > 1:
            # We are working with GEIS group syntax
            _indx = str(extn[:extn.find('/')])
            _extn = [int(_indx)]
        elif isinstance(extn, str):
            # Only one extension value specified...
            if extn.isdigit():
                # We only have an extension number specified as a string...
                _nextn = int(extn)
            else:
                # We only have EXTNAME specified...
                _nextn = extn
            _extn = [_nextn]
        else:
            # Only integer extension number given, or default of 0 is used.
            _extn = [int(extn)]

    else:
        _fname = filename
        _extn = None
    return _fname,_extn
178520
def file_name_without_extension(path):
    
    if path is None:
        return None
    return os.path.splitext(os.path.basename(path))[0]
662004
def extract_extension(path):
    
    filename = os.path.basename(path)
    parts = filename.split(".")
    if len(parts) == 1:
        return filename, None
    else:
        return ".".join(parts[:-1]), parts[-1]