From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: expand-file-name, DOS/Windows, and directory separator Date: Tue, 15 Feb 2022 22:24:49 +0200 Message-ID: <83mtir3mjy.fsf@gnu.org> References: <87czjodn8m.fsf@ericabrahamsen.net> <87wnhvdim4.fsf@ericabrahamsen.net> <83o8373ntc.fsf@gnu.org> <87sfsjdgz7.fsf@ericabrahamsen.net> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="668"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eric Abrahamsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Feb 15 21:26:04 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nK4Oi-000AXc-Gd for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Feb 2022 21:26:04 +0100 Original-Received: from localhost ([::1]:37962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nK4Og-0006kY-VS for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Feb 2022 15:26:02 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nK4NU-0005yA-QF for emacs-devel@gnu.org; Tue, 15 Feb 2022 15:24:48 -0500 Original-Received: from [2001:470:142:3::e] (port=37070 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nK4NU-00070L-Fd; Tue, 15 Feb 2022 15:24:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=rZf7B25kHcXLAuXqJs4PGuqapcadlAJP8cMINyb0Oh8=; b=lKL0mNJNSDRR UuwQTrIwCkPhCzbcNYHH04MF0FD4JjSWHX85tWCbPWGRAIq/nYOi68V2hYM9D4XbU40xx01OGFskJ bW6a+FqssX3cx5gPUhXCDXX9a4I+elmV+EzlqalfoXCSPmNyPOKX8ks+73o5P6Fd9y2YCWpAQT4QU JBjAPPKfi4s7Ic8s6CuD+uUGjqYQVDnrUiaI2bAO+dvHHVTqFS4RYIlZde/sSdukmhNW4JFgRzu4z JFVGMTFHKM2wwWMoZ3daHOPWPNYJLV1ouKJCqcOldPCuaCOKKVzDR5HYflJE/KKwBID3I1xqkE7zh ML6XeCFvvWAfV8eF7EE3eQ==; Original-Received: from [87.69.77.57] (port=4267 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nK4NT-0001T5-Ug; Tue, 15 Feb 2022 15:24:48 -0500 In-Reply-To: <87sfsjdgz7.fsf@ericabrahamsen.net> (message from Eric Abrahamsen on Tue, 15 Feb 2022 12:15:08 -0800) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:286351 Archived-At: > From: Eric Abrahamsen > Date: Tue, 15 Feb 2022 12:15:08 -0800 > > >> (file-name-split (expand-file-name "/")) > > > > file-name-split is one of the functions that support both styles of > > slashes, so you don't need to call expand-file-name at all. (And "/" > > is not really an absolute file name on Windows anyway). > > The `expand-file-name' is in there to collapse multiple consecutive > directory separators, which happens in the wild, as `file-name-split' > doesn't do that by itself. Then do call expand-file-name, but you don't need to assume anything about slashes in the result. > Just running this, where I've doubled the slashes so as not to raise > an error: > > (file-name-split "C:\\Users\\eric\\random") > > Just returns the whole string. I bet you did that on Unix? Because here on MS-Windows it returns the expected ("" "Users" "eric" "random") > This code has to handle all the weirdness of different systems and > filesystem layouts and search engines, so I'm being a little paranoid > about it. You don't need to be paranoid. Emacs's file-name related primitives are supposed to handle file names on all the supported systems; anything else is a bug that should be fixed.