all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Pascal Quesseveur <pquessev@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Function to know weither a dir is local or remote
Date: Thu, 20 Oct 2022 10:27:23 +0300	[thread overview]
Message-ID: <Y1D4Ww5I7gZq7I7F@protected.localdomain> (raw)
In-Reply-To: <825ygfngbw.fsf@gmail.com>

* Pascal Quesseveur <pquessev@gmail.com> [2022-10-20 10:04]:
> Hello,
> 
> I wanted to know if there is a function to know weither a file path
> denotes a local or a remote file.

file-remote-p is a byte-compiled Lisp function in ‘files.el’.

(file-remote-p FILE &optional IDENTIFICATION CONNECTED)

Test whether FILE specifies a location on a remote system.
A file is considered remote if accessing it is likely to
be slower or less reliable than accessing local files.

‘file-remote-p’ never opens a new remote connection.  It can
reuse only a connection that is already open.

Return nil or a string identifying the remote connection
(ideally a prefix of FILE).  Return nil if FILE is a relative
file name.

When IDENTIFICATION is nil, the returned string is a complete
remote identifier: with components method, user, and host.  The
components are those present in FILE, with defaults filled in for
any that are missing.

IDENTIFICATION can specify which part of the identification to
return.  IDENTIFICATION can be the symbol ‘method’, ‘user’,
‘host’, or ‘localname’.  Any other value is handled like nil and
means to return the complete identification.  The string returned
for IDENTIFICATION ‘localname’ can differ depending on whether
there is an existing connection.

If CONNECTED is non-nil, return an identification only if FILE is
located on a remote system and a connection is established to
that remote system.

Tip: You can use this expansion of remote identifier components
     to derive a new remote file name from an existing one.  For
     example, if FILE is "/sudo::/path/to/file" then

       (concat (file-remote-p FILE) "/bin/sh")

     returns a remote file name for file "/bin/sh" that has the
     same remote identifier as FILE but expanded; a name such as
     "/sudo:root@myhost:/bin/sh".

  Other relevant functions are documented in the file group.
  Probably introduced at or before Emacs version 22.1.

-- 
Jean

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

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



  parent reply	other threads:[~2022-10-20  7:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20  6:45 Function to know weither a dir is local or remote Pascal Quesseveur
2022-10-20  7:01 ` Eli Zaretskii
2022-10-20  7:27 ` Jean Louis [this message]
2022-10-20  8:13   ` Pascal Quesseveur
2022-10-20  8:59     ` Eli Zaretskii
2022-10-20  9:35       ` Pascal Quesseveur
2022-10-20 10:27         ` Eli Zaretskii
2022-10-20 12:54           ` Pascal Quesseveur
2022-10-20 16:16             ` Eli Zaretskii
2022-10-21  7:46               ` Pascal Quesseveur
2022-10-21 10:45                 ` Eli Zaretskii
2022-10-21 17:00                 ` tomas
2022-10-25 17:01                   ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-25 17:37                     ` tomas
2022-10-26  6:41                       ` Pascal Quesseveur
2022-10-26  8:25                         ` Michael Albinus
2022-10-26  8:59                           ` Pascal Quesseveur
2022-10-20 17:39             ` Michael Albinus
2022-10-21  7:47               ` Pascal Quesseveur

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y1D4Ww5I7gZq7I7F@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=pquessev@gmail.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.