Windows

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:

rmdir1

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.

Subscribe to VirtualizationHowto via Email 🔔

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.