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
Asatoma SadgamayaAnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
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
ste5anSenior DeveloperCommented:
hmm, there are no users in DOS..
Shaun VermaakTechnical SpecialistCommented:
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

Gerwin Jansen, EE MVETopic Advisor Commented:
Really DOS? No cmd command prompt you mean?

Try this:

C:\>DEL /F <filename>

But as already said: when the file is opened by some application, deleting will likely fail.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Asatoma SadgamayaAnalystAuthor Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.