emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how having the basename of a file or directory


From: Stefan Monnier
Subject: Re: how having the basename of a file or directory
Date: Mon, 31 Jan 2011 10:29:05 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

> Yes thanks, that's work too, but it would be nice to do not have to take
> care of that:

> (file-name-nondirectory "path/to/a/directory")
> should return ==> directory

It does.

> (file-name-nondirectory "path/to/a/file")
> should return ==> file

It does.

> So modifying `file-name-nondirectory' or creating a basename function
> or macro like:

> (defun basename (fname)
>   (if (file-directory-p fname)
>       (let ((dirname (directory-file-name fname)))
>         (file-name-nondirectory dirname))
>       (file-name-nondirectory fname)))

That won't work on (basename "/non/existing/thing/").
You really want to use (file-name-nondirectory (directory-file-name fname))


        Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]