0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

エクスプローラーのアドレスバーから「フォルダを開く」【VSCode】

Last updated at Posted at 2025-10-21

レコーディング 2025-10-21 140820.gif

背景

  • cmdコマンドのようにエクスプローラーのアドレスバーから「今いるディレクトリ」をVSCodeに渡したい
    • エクスプローラーを開いている状態から以下の操作をしたくない
      • 右クリックからCodeで開く
      • VSCodeを開いてからフォルダを開く(ctrl k ctrl o)
  • 任意の文字列で起動+コマンドプロンプトを非表示を両立したい

準備(高速)

右クリックからCodeで開くことすら面倒くさいあなた(私1)に向けて

必要なファイル作成とPathを通すスクリプトです。
PowerShellで2ファイルを配置したいディレクトリに移動してコピペしてください。そのディレクトリにPathが通ります。

$scriptDir = (Get-Location).Path

$vbsContent = @"
Set ws = CreateObject("WScript.Shell")
ws.Run "code .", 0, False
"@
Set-Content -Path "$scriptDir\vsc.vbs" -Value $vbsContent

$batContent = 'vsc.vbs'
Set-Content -Path "$scriptDir\vsc.bat" -Value $batContent

$currentPath = [System.Environment]::GetEnvironmentVariable("Path", "User")

# 既にPathに登録されているかチェック
if ($currentPath -like "*$scriptDir*") {
    Write-Host "Path is already set."
} else {
    $newPath = $currentPath + ";" + $scriptDir
    [System.Environment]::SetEnvironmentVariable("Path", $newPath, "User")
    Write-Host "Added '$scriptDir' to Path."
}

準備

準備(高速) を手作業で行う方法です。
パスが通ったディレクトリに以下の2ファイルを作成します。
(私はC:\scriptsをPathに追加しています。)
ファイル名はお好みで

vsc.bat
vsc.vbs
vsc.vbs
Set ws = CreateObject("WScript.Shell")
ws.Run "code .", 0, False

使用方法

  1. アドレスバーをフォーカスする(Alt D)
  2. vsc(またはお好みのファイル名)を打ち込んで確定
  3. VSCodeでディレクトリが開かれる

解説

.bat

アドレスバーから呼び出されるファイルです。
vbsファイルを呼び出します。

.vbs

code .を実行します。
引数に0を与えることでウィンドウを非表示に出来ます。
また、Falseを与えるとVSCodeの終了を待たずに処理を完了させることができます。

おわりに

参考記事で紹介されているcmd /k code. & exit等をエイリアス登録してもうまくいくかもしれません!
(永続化が面倒で、手が出せてません...)

参考

  1. 前のpcに導入してたやつ(この記事の内容)を使いたいなーと思って3ヶ月経ちました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?