How to delete all files and folders in a folder by cmd call

I use Windows.

I want to delete all files and folders in a folder by system call.

I may call like that:

>rd /s /q c:\destination
>md c:\destination

Do you know an easier way?


Solution 1:

No, I don't know one.

If you want to retain the original directory for some reason (ACLs, &c.), and instead really want to empty it, then you can do the following:

del /q destination\*
for /d %x in (destination\*) do @rd /s /q "%x"

This first removes all files from the directory, and then recursively removes all nested directories, but overall keeping the top-level directory as it is (except for its contents).

Note that within a batch file you need to double the % within the for loop:

del /q destination\*
for /d %%x in (destination\*) do @rd /s /q "%%x"

Solution 2:

del c:\destination\*.* /s /q worked for me. I hope that works for you as well.

Solution 3:

I think the easiest way to do it is:

rmdir /s /q "C:\FolderToNotToDelete\"

The last "\" in the path is the important part.