From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.devel Subject: Re: how having the basename of a file or directory Date: Mon, 31 Jan 2011 17:30:26 +0100 Message-ID: <87y6613ujh.fsf@gmail.com> References: <8739o9ilfs.fsf@gmail.com> <877hdl4grd.fsf@uwakimon.sk.tsukuba.ac.jp> <87y661h2ju.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1296491729 2839 80.91.229.12 (31 Jan 2011 16:35:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 31 Jan 2011 16:35:29 +0000 (UTC) Cc: "Stephen J. Turnbull" , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 31 17:35:24 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pjwio-0005cd-QR for ged-emacs-devel@m.gmane.org; Mon, 31 Jan 2011 17:35:22 +0100 Original-Received: from localhost ([127.0.0.1]:51205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pjwio-0004do-3x for ged-emacs-devel@m.gmane.org; Mon, 31 Jan 2011 11:35:22 -0500 Original-Received: from [140.186.70.92] (port=53394 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pjwe9-0002XR-HI for emacs-devel@gnu.org; Mon, 31 Jan 2011 11:30:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pjwe6-00054h-La for emacs-devel@gnu.org; Mon, 31 Jan 2011 11:30:32 -0500 Original-Received: from mail-ww0-f49.google.com ([74.125.82.49]:61396) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pjwe6-00054L-Gw for emacs-devel@gnu.org; Mon, 31 Jan 2011 11:30:30 -0500 Original-Received: by wwb17 with SMTP id 17so6113498wwb.30 for ; Mon, 31 Jan 2011 08:30:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=UhD6mnR0WIygvUFr5ji8odloxq1reSKQjOA8wcy6EKY=; b=hfjm3fNlRc1w+oigQWhCK83hv1oFdNjvUBBzHIvth8Me93oFlDb0D/m+VQBr23G3dx /gjRyXRMXl29OVaep/c63AqAXnCqJo8NxMx6R4XJ+zfZhy6iAP87cu6qCJe4wTYj4lHF +h50zoE4Y1pxdHzWAVO9sAl+mbwtAmQW29zsA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=ep3ebm7YmbDdqU9I8q4Mn14Ab6zflZOolz53eJNOSylUz6ePDlcTqO9cId2ebakY8m SPuhElW1tJfsMN9Ks3JQqff6wJV/sBmk9zfWldt53bUjP4b74zdl6ELO1xXeaqaAGJF2 cPp10e0ZLLLmPrMLppbqIByHzRIXnDMSRTf50= Original-Received: by 10.227.136.9 with SMTP id p9mr4376500wbt.30.1296491428703; Mon, 31 Jan 2011 08:30:28 -0800 (PST) Original-Received: from thierry-MM061 (63.211.85-79.rev.gaoland.net [79.85.211.63]) by mx.google.com with ESMTPS id f27sm4417196wbf.19.2011.01.31.08.30.27 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 31 Jan 2011 08:30:28 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Mon, 31 Jan 2011 10:29:05 -0500") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.49 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:135317 Archived-At: Stefan Monnier writes: >> 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)) Indeed, yes, thanks Stefan, but something like (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))) would work and be useful. -- A+ Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997