

I tried the command, but someone has created the directory repeatedly and now I can not removed the base directory. Otherwise rmdir throws ‘Access denied’ error. To delete a directory, you should have appropriate access permissions on the directory. forfiles /P directory_path /M * /C "cmd /c if del /P directory_path /M * /C "cmd /c if rmdir /S /Q works in 2 steps – the first command deletes all files, whereas the second one deletes all subdirectories. Rather the below commands should do the trick. rmdir /Q /S does not work here as it deletes the parent directory too. The usecase here is to delete all the contents of the directory but keep the parent directory so that we do not need to create it again.

rmdir /Q /S "folder with spaces in the name" Delete contents of a directory but keep the directory

Rmdir can delete files with whitespaces in the name, you just need to wrap up the folder name in double quotes as shown in the below example. Deleting directory with white spaces in the name This command works on Windows 2000, Windows XP, Server 2003, Vista, Windows 7 and 10. We can also use ‘rd’ in place of ‘rmdir‘. To force delete directory, without being asked for confirmation, we can use /Q switch. C:>rmdir /S nonemptydirĬ:> Force delete a folder without confirmation Use /s option to delete the folder contents along with the folder. The simple rmdir does not work for folders having some content.
