How do I subtract paths in elisp?

elisp

Solution

Use `file-relative-name`:

(file-relative-name "/foo/bar/baz/gig" "/foo/bar/")    ;   => "baz/gig"

Documented in the Elisp manual under "Relative File Names".

Problem

I've got two paths, one a subset of the other `/foo/bar/` and `/foo/bar/baz/gig`. The path I'd like to extract is `baz/gig`, the relative path of the file from the dir.

Original source