The Modular DocBook Stylesheets
PrevDSSSL LibraryNext

file-extension

Name

file-extension — Return the extension of a filename

Synopsis

(file-extension filespec)

Description

Returns the extension of a filename. The extension is the last "."-delimited part of the name. Returns "" if there is no period in the filename.

Author

Norman Walsh, <norm@berkshire.net>

Source Code

(define (file-extension filespec) 
  ;; Return the extension of a filename
  (let* ((pathparts (match-split filespec "/"))
	 (filename  (list-ref pathparts (- (length pathparts) 1)))
	 (fileparts (match-split filename "."))
	 (extension (list-ref fileparts (- (length fileparts) 1))))
    (if (> (length fileparts) 1)
	extension
	"")))

PrevHomeNext
exptUpfind-first-char