How to Delete everything in a directory suppressing errors

Recently in working with a client who was trying to delete old profiles from a directory, they were running into problems with certain folders in the directory.  After it taking forever to even start the delete process in Windows, when an error would be encountered, the process would stop.  This can lead to a very tedious and frustrating process of watching the delete action take place and then trying to catch it when it fails to start it all over again.  However, this is the Windows GUI so one can only expect issues.  Is there a command line way to do this which is much less painful?  Absolutely!

By using the rmdir command, we can kick off the delete process using switches which will surpress any confirmations or errors from killing the process and also delete subdirectories that are not empty which is another problem one will encounter if trying to use only the del command to delete the files.  So here is the command in full:

rmdir /s /q c:\yourdirectory

Note above, the “c:\yourdirectory” is any directory that you want to purge.  Take a look at the screenshot below of the command syntax for what the switches mean and will do:


One thing to be caution of about this command though is that it also deletes the parent directory.  So if there is something that is very critical about the directory itself, you might need to do something else for the delete.  Otherwise this is a great command to purge a directory and suppress errors that would otherwise keep the process from completing successfully.

Back to top button