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


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?

Best Solution

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.


This silently removes the folder and all files and subfolders.