I want to replace some files in folder, and I see that there are multiple process under the folder that prevent me from doing that.
How can I kill all process process that run under a folder?
I want to replace some files in folder, and I see that there are multiple process under the folder that prevent me from doing that.
How can I kill all process process that run under a folder?
Using powershell:
cd "%*DestinationPath*%"
Get-Process | ?{$_.path -and (test-path (split-path $_.path -leaf ))} | Stop-Process -Force
If you prefer using batch (because cmd is one of your tags), use wmic process
:
@echo off
set "dir=YOUR PATH HERE"
for /f "skip=1 tokens=*" %%a in ('wmic process get executablepath') do (
for /f "eol= tokens=*" %%A in ("%%a") do (
echo(%%~dpA | findstr /I %dir% >nul 2>&1
if %ERRORLEVEL% equ 0 taskkill /F /IM "%%~nxA"
)
)
Note: This is NOT foolproof, all processes with the same name will get killed