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: Thierry Volpiatto
Subject: Re: how having the basename of a file or directory
Date: Mon, 31 Jan 2011 21:39:49 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2.92 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> (defun basename (fname)
>>   (if (or (file-directory-p fname)
>>           (string-match "/$" fname))
>>       (let ((dirname (directory-file-name fname))) 
>>         (file-name-nondirectory dirname))
>>       (file-name-nondirectory fname)))
>
> If, as Karl suggests, your point is that you want a `basename' function,
> then maybe we could add such a function (I'm really not convinced it's
> worth the trouble.  Better would be to add a paragraph in the manual,
> I think), but I still insist that the above definition is wrong.
The above definition is not wrong, but it have unneeded code.
However the unneeded code explain clearly what happen.

> It should be
>
>   (defun file-basename (file)
>     (file-name-nondirectory (directory-file-name file)))
Yes.
Because the name of this function (i.e directory-file-name), i didn't think
to call it on a filename, but it return the filename yes.
Maybe confusion with file-name-directory.
(always need to look manual when using all these file-name-*,
directory-file-* etc... functions)

Adding a basename function is just a first step to simplify all that.

-- 
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 



reply via email to

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