[Top][All Lists]
[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 09:59:01 +0100 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.2.92 (gnu/linux) |
Hi Stephen,
"Stephen J. Turnbull" <address@hidden> writes:
> Thierry Volpiatto writes:
>
> > (defun basename (fname)
> > (if (file-directory-p fname)
> > (let ((dirname (directory-file-name fname)))
> > (file-relative-name
> > dirname (file-name-directory dirname)))
> > (file-name-nondirectory fname)))
>
> (file-name-nondirectory (directory-file-name PATH))
>
> should work (modulo I'm testing in XEmacs, but I can't imagine that we
> differ in this respect).
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
(file-name-nondirectory "path/to/a/file")
should return ==> file
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)))
would be nice.
--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
- how having the basename of a file or directory, Thierry Volpiatto, 2011/01/31
- how having the basename of a file or directory, Stephen J. Turnbull, 2011/01/31
- Re: how having the basename of a file or directory,
Thierry Volpiatto <=
- Re: how having the basename of a file or directory, Andreas Schwab, 2011/01/31
- Re: how having the basename of a file or directory, Thierry Volpiatto, 2011/01/31
- Re: how having the basename of a file or directory, Andreas Schwab, 2011/01/31
- Re: how having the basename of a file or directory, Thierry Volpiatto, 2011/01/31
- Re: how having the basename of a file or directory, Andreas Schwab, 2011/01/31
- Re: how having the basename of a file or directory, Stefan Monnier, 2011/01/31
- Re: how having the basename of a file or directory, Thierry Volpiatto, 2011/01/31
- Re: how having the basename of a file or directory, Karl Fogel, 2011/01/31
- Re: how having the basename of a file or directory, Stefan Monnier, 2011/01/31
- Re: how having the basename of a file or directory, Thierry Volpiatto, 2011/01/31