エディタからエクスプローラーを起動する

  • 最近、WordやExcelの仕事ばかりになってしまい、プログラムを書いてない
  • ファイル共有先に色々書類を作成するが、フォルダ階層が深くて毎回探すのが面倒
  • エディタに色々パスをメモするので、カーソル位置にあるパスをエクスプローラーで開くようにしてみた

xyzzy

  • ネットで見つけたのを少し直しただけ
  • 行の先頭から最後までをエクスプローラーの引き数に渡す
  • フォルダでなくファイルの場合は、/selectを付ける
  • そういえば、新人さんの目標に「関数型言語を使えるようになる」っていうのがあったけど、自分はまだ使えてないな
;;; open-explorer
(defun open-explorer (fn)
  (flet ((get-arg ()
	   (if fn
	       (if (file-directory-p fn)
		   (concat "/e," (map-slash-to-backslash fn))
		 (concat "/e,/select," (map-slash-to-backslash fn)))
	     (concat "/e," (map-slash-to-backslash (si:system-root))))
	   ))
    (call-process
     (concat (get-windows-directory) "explorer " (get-arg)))
    )
  )

;;; open path in current position with explorer (C-x x) (C-3)
(defun open-path-with-explorer ()
  (interactive)
  (let (path)
    (save-excursion
      (beginning-of-line)
      (setq path (buffer-substring (point)
				   (progn (end-of-line) (point)))))
    (open-explorer path)
    ; (message-box path)
    )
  )
(global-set-key '(#\C-x #\x) 'open-path-with-explorer)
(global-set-key '(#\C-3) 'open-path-with-explorer)
参考

カーソル位置にあるパスを解釈してファイルを開いたりする

秀丸

  • 秀丸マクロで書くと短いな
// エクスプローラで開く
// ファイル名またはパス名のある行にカーソルを置いて実行する
$fname = gettext2(0, lineno, linelen2, lineno);
if ((existfile($fname, 1 ) & 0x00000010) != 0) {
	// ディレクトリ
	run "explorer /e,"+ $fname;
}
else {
	// ファイル
	run "explorer /e,/select,"+ $fname;
}