MaxScriptTip: 指定ディレクトリをエクスプローラで開く

5月 29, 2016
ディレクトリ(フォルダ)をエクスプローラで開くには、リファレンスにある通りShellLaunchを使用します。 DOSCommandを利用しても同じ事が出来ますが、DOSウィンドウを開いたりしたくないのでこちらを利用します。

今回はせっかくなので、指定したファイルを選択状態にして開くオプションも付けてみます。
-- エクスプローラで対象を開く
-- thePath  select
-- File   true  : 指定したファイルを選択状態でディレクトリを開く。
-- File   false : 指定ファイルを関連付けられたプログラムで開く。
-- Directory  true  : 指定ディレクトリを選択状態で1つ上のディレクトリを開く。
-- Directory  false : 指定ディレクトリそのものを無選択状態で開く。
fn openWithExploer thePath select:true =
(
 thePath = pathConfig.normalizePath thePath
 if select then
  ShellLaunch "explorer.exe" (stringFormat "/e,/select,\"{0}\"" thePath)
 else
  ShellLaunch "explorer.exe" (stringFormat "/e,\"{0}\"" thePath)
)
使ってみる。
-- notepad.exeを選択した状態でWindowsフォルダを開く
openWithExploer @"C:/Windows/notepad.exe" select:true
-- Autodeskフォルダを選択した状態でProgram Filesフォルダを開く
openWithExploer @"C:/Program Files/Autodesk" select:true
-- 単にAutodeskフォルダを開く
openWithExploer @"C:/Program Files/Autodesk" select:false
どうでしょうか?

ちなみに、select:false状態でファイル等を指定すると、関連付けられたプログラムで単にそのファイルが開かれます。
select:trueでディレクトリを指定すると、その1つ上のフォルダが開かれるのもミソですね。

今回は短めですが、こんな感じで。

Related Articles