DSSSL Library Reference: Part of the Modular DocBook Stylesheet distribution
Prev |  | Next

# 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, <ndw@nwalsh.com>

## Source Code

    (define (file-extension filespec)
      ;; Return the extension of a filename
      (if (string? filespec)
          (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
    	    ""))
          ""))

Prev | Home | Next
directory-depth | Up | copy-string