操作系统的默认资源管理器打开包含当前文件的文件夹的最简单方法是什么?


10

通过操作系统的默认资源管理器(例如,对于Windows操作系统,例如explorer.exe)打开包含当前文件的文件夹的最简单方法是什么?


1
我有一个预感(浏览文件的默认目录目录)可以做到,它可以在finder的osx上运行,我认为它可以在Windows上运行,但是无法测试。
Jordon Biondo

@JordonBiondo有效!请将您的评论转换为答案。
命名

Answers:


14

browse-url-of-file给定目录后,使用应该可以工作。

您可以执行如下命令来打开当前文件的目录:

(defun browse-file-directory ()
  "Open the current file's directory however the OS would."
  (interactive)
  (if default-directory
      (browse-url-of-file (expand-file-name default-directory))
    (error "No `default-directory' to open")))

然后M-x browse-file-directory应在操作系统的文件浏览器中打开目录。


在Windows中,与emacs 25. *的兼容性很小,但在Windows上与emacs 26.1兼容,该解决方案可以正常工作。
命名

是否可以像在VS中那样选择文件?请参阅dev.to/devmount/23-lesser-known-vs-code-shortcuts-as-gif-80中的
user3341592


1

使用默认的资源管理器程序和当前文件夹运行shell-commandM+ !),例如对于MS Windows,explorer .


0

首先将完整路径复制到剪贴板:

;; you need install xsel under Linux
;; xclip has some problem when copying under Linux
(defun copy-yank-str (msg &optional clipboard-only)
  (unless clipboard-only (kill-new msg))
  (cond
   ;; display-graphic-p need windows 23.3.1
   ((and (display-graphic-p) x-select-enable-clipboard)
    (x-set-selection 'CLIPBOARD msg))
   (t (with-temp-buffer
        (insert msg)
        (shell-command-on-region (point-min) (point-max)
                                 (cond
                                  ((eq system-type 'cygwin) "putclip")
                                  ((eq system-type 'darwin) "pbcopy")
                                  (t "xsel -ib")))))))

(defun cp-fullpath-of-current-buffer ()
  "copy full path into the yank ring and OS clipboard"
  (interactive)
  (when buffer-file-name
    (copy-yank-str (file-truename buffer-file-name))
    (message "file full path => clipboard & yank ring")))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.