سؤال

How can I link to files on network drives in a Windows environment from Org-mode?

I get the error:

eval: ShellExecute failed: The system cannot find the file specified.

with this sort of link:

[[//share/path/to/file.csv]]

هل كانت مفيدة؟

المحلول

I also had the same problem. I traced it to org-open-at-point transforming the PATH to something that w32-shell-execute cannot open. Using the defadvice below, I am able to open // and \ network paths.

(defadvice w32-shell-execute (around 
                              workaround-for-org-w32-shell-execute
                              activate)
  "Replace w32-shell-execute PATH directory seperators to Windows
backslash when PATH starts with '//' (i.e. Network path). This
allows allowing org-mode links in org-mode files like
[[\\\\myserver\\mypath\\mydoc.doc][mydoc.doc]] to be opened by
org-open-at-point. Forward slashes / are also accepted.

org-open-at-point transforms the links to //../../ but
unfortunately w32-shell-execute does not accept that."
  (let ((operation (ad-get-arg 0))
        (path      (ad-get-arg 1)))
    (when (and (string-equal operation "open")
               (eql (string-match "//" path 0) 0))
      (setq path (replace-regexp-in-string "/" "\\\\" path))
      ;; debug (message "Opening %s" path)
      (ad-set-arg 1 path))
    ad-do-it))

Try [[//127.0.0.1/c$$]]

This is a quick and dirty fix, but "it works on my machine".

Verified on Emacs 24.2, Org-mode 7.9.11.

Edit: The comment about "However, a big usage case for me is opening other types of files (eg. MS Office files)" works for me when I add the following associations to org-mode. I can open Microsoft Word, Excel, etc, using normal org-mode urls like [[\server\share\piyo.doc]]

(mapc (lambda (file-name-matcher)
    (add-to-list 'org-file-apps
                 (cons file-name-matcher 'default) 'append))
  (list "\\.doc\\'"
        "\\.xls\\'"
        "\\.ppt\\'"))

Edit: The comment about "[[file+sys:]]" is "open [a file] via OS, like double-click", which can be achieved with the above associations. On my Windows computer, I have not needed "[[file+sys:]]".

نصائح أخرى

Some parts of Windows, and some Windows applications, do not support UNC paths. Emacs does, but it looks like you (or org-mode) are trying to execute some program, rather than simply use find-file to view the file in Emacs. The workaround would be to mount //share/path as X: and use [[X:/to/file.csv]] as your link.

If your UNC path happens to include one of the administrative shares associated with the remote disk drivers (like \server\c$ or \server\d$, you need to double up the $ after the disc letter so that they look like \server\c$$ or \server\d$$

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top