windowsでもterminalのopenが使いたい

macのterminalで [open] コマンドが便利でよく使うんだけど
windowsでも使いたいのでvbsで書いてみた。
(terminalからファインダーを開く)

Option Explicit
Dim WShell, oExec
Set WShell = WScript.CreateObject("WScript.Shell")
Dim openPath
Dim numArgs, argPath
numArgs = WScript.Arguments.Count

'[.][./]は引数無しと一緒(カレントパス)
if numArgs > 0 then
	argPath = Replace(WScript.Arguments.Unnamed.Item(0), "/", "\")
	if argPath = "." or argPath = ".\" then
		openPath = WShell.CurrentDirectory
	'slashが引数としてわたった場合を書きたかったけど、引数として正しく渡らない模様
	'elseif argPath = "/" then
	'	openPath = "c:\"
	else
		openPath = argPath
	end if
else
	openPath = WShell.CurrentDirectory
end if

Set oExec = WShell.Exec("explorer /root," & openPath)

Set WShell = nothing
Set oExec = nothing

あとはpathの通るところopen.vbsとして置くだけ。


参考:Windows エクスプローラのコマンドライン オプション