From: Jean Louis <bugs@gnu.support>
To: Bruno Barbier <brubar.cs@gmail.com>
Cc: Edgar Vincent <e-v@posteo.net>, eliz@gnu.org, help-gnu-emacs@gnu.org
Subject: Re: Why does (file-exists-p "") return t?
Date: Sat, 11 Feb 2023 14:28:55 +0300 [thread overview]
Message-ID: <Y+d79xn1QEojXjGy@protected.localdomain> (raw)
In-Reply-To: <63e7697c.1c0a0220.a6be.a36d@mx.google.com>
* 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/
next prev parent reply other threads:[~2023-02-11 11:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 10:41 Why does (file-exists-p "") return t? Edgar Vincent
2023-02-09 10:56 ` Gregory Heytings
2023-02-09 11:10 ` Edgar Vincent
2023-02-09 13:36 ` Eli Zaretskii
2023-02-09 21:05 ` Edgar Vincent
2023-02-10 4:20 ` Jean Louis
2023-02-11 10:10 ` Bruno Barbier
2023-02-11 11:28 ` Jean Louis [this message]
2023-02-11 19:34 ` Bruno Barbier
2023-02-11 10:39 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y+d79xn1QEojXjGy@protected.localdomain \
--to=bugs@gnu.support \
--cc=brubar.cs@gmail.com \
--cc=e-v@posteo.net \
--cc=eliz@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).