Windows

How to Delete everything in a directory suppressing errors

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 a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He 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. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

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.