When you try to rename a file or folder in Windows,
The action can't be completed because the file is open in another program.```bash PS C:\pg\rails> mv tool tooltmp mv : The action can't be completed because the file is open in another program. At line:1 char:1 + mv tool tooltmp + ~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (C:\pg\rails\tool:DirectoryInfo) [Move-Item], IOException + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand ``` you may get this error.
If we could identify the process that has the file open and taskkill it, that would be nice…
There are several ways to do this:
- Search with the OPENFILES command
- Use Sysinternals Suite Handle command (recommended)
- [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>Use Microsoft software
Process Monitor
Process Explorer</li>
</ul>
References:
<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>