help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Why does (file-exists-p "") return t?


From: Jean Louis
Subject: Re: Why does (file-exists-p "") return t?
Date: Sat, 11 Feb 2023 14:28:55 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Bruno Barbier <brubar.cs@gmail.com> [2023-02-11 13:10]:
> > * Edgar Vincent <e-v@posteo.net> [2023-02-10 00:11]:
> >> I didn’t know that file-exists-p used expand-file-name, but it does seem 
> >> obvious.
> >
> > To avoid the problem maybe you should use `expand-file-name' before
> > you check it with `file-exists-p'
> >
> > As otherwise you may check the wrong path.
> 
> Why ?
> 
> One of the first thing `file-exists-p' is doing is to call
> `expand-file-name' to expand the file name.  I don't see how calling
> `expand-file-name' before would help.

I understand you and I am sure in most use cases it is not necessary
as it will be expanded later. 

Sometimes I wish to expand it before for reason that
`default-directory' sometimes changes:

- practically, I sometimes wish to have "/home/user/public_html" as part of
  directory, and to check for file existence only if that is part of
  the path.

- When I use Tramp, my program my give me wrong answer by design, as I
  maybe did not want to check anything on remote system, but program
  is not aware of it by alone.

Of course, to avoid similar cases, I can keep `default-directory':

(let ((default-directory "something"))
 (before doing something else))

There is pertinent use case where I am receiving "" from database, and
instead of `expand-file-name' I want to consider it "no file name",
and checking would take place only when there is no empty string, as
otherwis I would get information how file exists for "" which is not
meant to be by design.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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