emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: expand-file-name, DOS/Windows, and directory separator


From: Eric Abrahamsen
Subject: Re: expand-file-name, DOS/Windows, and directory separator
Date: Tue, 15 Feb 2022 12:46:43 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>> Date: Tue, 15 Feb 2022 12:15:08 -0800
>> 
>> >> (file-name-split (expand-file-name <file> "/"))
>> >
>> > 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.

Got it.

>> 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")

As I was hoping it would! But yes, I only have unix-like boxes to test
on.

>> 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.

Ignorance breeds magical thinking :) Thanks for the reassurance, I'll go
ahead and update this.




reply via email to

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