Windowsでファイル名やフォルダ名を変更しようとしたりすると、
ファイルが別のプロセスで使用されているため、プロセスはファイルにアクセスできません。```bash PS C:\pg\rails> mv tool tooltmp mv : ファイルが別のプロセスで使用されているため、プロセスはファイルにアクセスできません。 発生場所 行:1 文字:1 + mv tool tooltmp + ~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (C:\pg\rails\tool:DirectoryInfo) [Move-Item], IOException + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand ``` って拒否されることがあります。
ファイルを開いているプロセスを特定して、それをtaskkillできればいいのですが…。
その方法はいくつかあるようです。
- OPENFILES コマンドで探す
- Sysinternals Suite Handle コマンドを使う(おすすめ)
- [Handle - Windows Sysinternals | Microsoft Docs](https://docs.microsoft.com/en-us/sysinternals/downloads/handle)
Nthandle v4.11 - Handle viewer Copyright (C) 1997-2017 Mark Russinovich Sysinternals - www.sysinternals.com
explorer.exe pid: 6588 type: File 11BC: C:\pg\RAILS\devise\db\migrate explorer.exe pid: 6588 type: File 1390: C:\pg\RAILS explorer.exe pid: 6588 type: File 1578: C:\pg\RAILS explorer.exe pid: 6588 type: File 2804: C:\pg\RAILS\devise\db\migrate explorer.exe pid: 6588 type: File 2FD8: C:\pg\RAILS\devise\app\views\devise\registrations explorer.exe pid: 6588 type: File 2FE0: C:\pg\RAILS\devise\app\views\devise\registrations powershell.exe pid: 16252 type: File 4C: C:\pg\RAILS\dev___ powershell.exe pid: 716 type: File 4C: C:\pg\RAILS\dev___ powershell.exe pid: 8924 type: File 4C: C:\pg\RAILS\english powershell.exe pid: 16488 type: File 4C: C:\pg\RAILS\devise powershell.exe pid: 16608 type: File 4C: C:\pg\RAILS\devise atom.exe pid: 19220 type: File 884: C:\pg\RAILS\english atom.exe pid: 19220 type: File AEC: C:\pg\RAILS\english atom.exe pid: 19228 type: File 6B8: C:\pg\RAILS\devise atom.exe pid: 19228 type: File 750: C:\pg\RAILS\devise cmd.exe pid: 16944 type: File 4C: C:\pg\RAILS\tool ruby.exe pid: 28104 type: File 4C: C:\pg\RAILS\tool ruby.exe pid: 11316 type: File 2BC: C:\pg\RAILS\tool\log\development.log ruby.exe pid: 11316 type: File 32C: C:\pg\RAILS\tool handle64.exe pid: 15084 type: File 4C: C:\pg\RAILS PS C:\pg\rails>
<ul>
<li>マイクロソフトのソフトウェアを使う
Process Monitor
Process Explorer</li>
</ul>
参考:
<ul>
<li>[[Windows] ファイルを開いているプロセスを見つける | mofu犬blog](http://mofuken.blogspot.com/2014/08/windows.html)</li>
<li>[「Windows」ファイルを開いているプロセスを特定する方法いろいろ - プログラム日記](http://a4dosanddos.hatenablog.com/entry/2015/07/30/020159)</li>
</ul>