How can I delete all files/subfolders in a given folder via the command prompt?

Solution 1:

You can do this using del and the /S flag (to tell it to remove all files from all subdirectories):

del /S C:\Path\to\directory\*

Solution 2:

The best Solution: e.g. i want to delete all files and sub-directories of parent directory lets say "C:\Users\Desktop\New folder\". The easy way is create batch file of below three commands.

cd C:\Users\Desktop\New folder\

del * /S /Q

rmdir /S /Q "C:\Users\Desktop\New folder\"

Here first it will clean all files in all sub-directories and then cleans all empty sub-directories. Since current working directory is parent directory i.e."\New folder", rmdir command can't delete this directory itself.

Solution 3:

Navigate to the parent directory:

pushd "Parent Directory"

Delete the sub folders:

rd /s /q . 2>nul

Solution 4:

rmdir "c:\pathofyourdirectory" /q /s

Don't forget to use the quotes and for the /q /s it will delete all the repositories and without prompting.