Search and delete directories

  • Thread starter Thread starter Philip Wagenaar
  • Start date Start date
P

Philip Wagenaar

How do I search for a directory on a windows xp machine
and delete the directory including all subfolders and
files in them?
 
Hi,

as far as I understand U loop through the folders for foldername and when
found, delete the folder including subfolders See code below. try it but be
careful cause it deletes without asking

LoopFolders ("C:\Temp")

Private Sub LoopFolders(ByVal nod As String)
Dim strPath As String = nod
Dim strDir As String

With nod
For Each strDir In Directory.GetDirectories(strPath)
' Path.GetFileName returns just the file name portion of the full
path returned from the GetDirectories method.
if strDir = SEARCHED_FOLDER then
strPath =
Directory.Delete(strPath, true) ' CAREFUL this doesn't ask
for confirmation it simply delete recursivly the folder and contents
end if
Next
End With
End Sub
 
Back
Top