From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: how having the basename of a file or directory Date: Mon, 31 Jan 2011 10:29:05 -0500 Message-ID: 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 1296490704 29042 80.91.229.12 (31 Jan 2011 16:18:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 31 Jan 2011 16:18:24 +0000 (UTC) Cc: "Stephen J. Turnbull" , emacs-devel@gnu.org To: Thierry Volpiatto Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 31 17:18:20 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 1PjwSJ-0003qv-BL for ged-emacs-devel@m.gmane.org; Mon, 31 Jan 2011 17:18:19 +0100 Original-Received: from localhost ([127.0.0.1]:58072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PjwSI-0003qb-IP for ged-emacs-devel@m.gmane.org; Mon, 31 Jan 2011 11:18:18 -0500 Original-Received: from [140.186.70.92] (port=57637 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pjvgv-0003Kx-6V for emacs-devel@gnu.org; Mon, 31 Jan 2011 10:29:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pjvgg-0003qN-J7 for emacs-devel@gnu.org; Mon, 31 Jan 2011 10:29:08 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:11093 helo=ironport2-out.pppoe.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pjvgg-0003q3-F9 for emacs-devel@gnu.org; Mon, 31 Jan 2011 10:29:06 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAM5jRk1MCpTp/2dsb2JhbACkeHS9KYVOBIUTj2g X-IronPort-AV: E=Sophos;i="4.60,404,1291611600"; d="scan'208";a="89946702" Original-Received: from 76-10-148-233.dsl.teksavvy.com (HELO ceviche.home) ([76.10.148.233]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 31 Jan 2011 10:29:05 -0500 Original-Received: by ceviche.home (Postfix, from userid 20848) id 22E3D660DC; Mon, 31 Jan 2011 10:29:05 -0500 (EST) In-Reply-To: <87y661h2ju.fsf@gmail.com> (Thierry Volpiatto's message of "Mon, 31 Jan 2011 09:59:01 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:135314 Archived-At: > 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