Jul
12
Written by:
Steve Gray
7/12/2010 9:23 AM
I need to search a directory and find all occurrences of a certain directory name and delete that folder and all contents. I’m using an application for handling photos and it created a directory called ‘50x40’ in a photo gallery directory to hold thumbnails. This directory is in each folder in the drive, and I count 176 of them. I’m too lazy to manually delete all those folders… and I have a long history spending 4 hours writing code to handle a task that I could have done in one.
At least I’m aware of my issues, right?
Code to search for a certain directory and delete it. You might need to IMPORT or set a reference to SYSTEM.IO
For Each s As String In Directory.GetDirectories("\\devshed04\photos\", "50x40", SearchOption.AllDirectories)
Directory.Delete(s, True)
Next s
As always, I welcome your comments!