How to delete files/subfolders in a specific directory at the command prompt in Windows

Deniz Zoeteman picture Deniz Zoeteman · Dec 27, 2009 · Viewed 999.8k times · Source

Say, there is a variable called %pathtofolder%, as it makes it clear it is a full path of a folder.

I want to delete every single file and subfolder in this directory, but not the directory itself.

But, there might be an error like 'this file/folder is already in use'... when that happens, it should just continue and skip that file/folder.

Is there some command for this?

Answer

Suresh picture Suresh · Apr 2, 2012

rmdir is my all time favorite command for the job. It works for deleting huge files and folders with subfolders. A backup is not created, so make sure that you have copied your files safely before running this command.

RMDIR "FOLDERNAME" /S /Q

This silently removes the folder and all files and subfolders.