Get last component of pathname in Common Lisp

While I can build a pathname e.g.

(make-pathname :directory '(:RELATIVE "dir" "subdir" "subsubdir"))

how do I get back subsubdir from a pathname like this (assuming it is a directory)? I need to extract the last dir from a pathname, just as this Unix command does:

$ basename /usr/local/share/
share

Upvotes: 3

Views: 1666

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139241

See the Common Lisp Hyperspec, the Filenames Dictionary

(first (last (pathname-directory some-pathname)))

Upvotes: 8

Related Questions