XK8ER
asked on
vb.net - remove empty directories
hello there,
I have a path lets say "c:\names" that contains about 300 different directories..
I would like to create a button that will look through all of the sub-directories and remove the empty ones..
how can I do that?
I have a path lets say "c:\names" that contains about 300 different directories..
I would like to create a button that will look through all of the sub-directories and remove the empty ones..
how can I do that?
ASKER
this is what im getting..
The directory is not empty.
>>subDirectory.Delete()
The directory is not empty.
>>subDirectory.Delete()
Try the below code instead
'Here's the code:
Public Sub CheckFolder(ByVal sourceFolderPath As String)
Dim di As New IO.DirectoryInfo(sourceFolderPath)
For Each directory As IO.DirectoryInfo In di.GetDirectories
If directory.GetFiles().Length = 0 AndAlso directory.GetDirectories.Length = 0 Then
directory.Delete()
End If
Next
End Sub
ASKER
the new code its not removing any directories..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot.. it works so good..
https://www.experts-exchange.com/questions/22839113/Check-for-and-delete-empty-folders.html?sfQueryTermInfo=1+10+30+empti+folder+remov
Below is the accepted answer from TheLearnedOne:
Open in new window