Link to home
Start Free TrialLog in
Avatar of Asatoma Sadgamaya
Asatoma SadgamayaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

DOS command to delete particular file/s from a folder

Hi,

I am looking for dos command to force delete file/files by its name from folder. No matter any user uses/open that file. I don't want all files in the foleder get deleted when I run this code. Thats the reason why I am asking for a code where I can put file names and that code will delete the files I needed.

Thank you
Avatar of NVIT
NVIT
Flag of United States of America image

Questions...
- What kind of file is it?
- What program is used to open it?
- Does the file reside on a server?

Some programs lock the file when it is opened, possibly preventing it from deletion

Servers can use the NET FILE or PSFILE command to force closure of shared  files
hmm, there are no users in DOS..
Pretty sure OP means CMD and not DOS

I would however use Powershell, somehing like this
Get-SmbOpenFile | Where-Object -Property sharerelativepath -match "SomeFile.txt" | Close-SmbOpenFile -Force
Get-ChildItem -Path C:\Temp -Include "SomeFile.txt" -File -Recurse | foreach { $_.Delete()}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Asatoma Sadgamaya

ASKER

thanks