
How to delete folders/files within a folder but not the folder itself
Hi!
I need to write a small program that deletes all folders and files within a
specified folder but not the folder itself.
So, for better understanding, heres my code:
the problem is, o.Name will be killed, too...
Is there a way to keep the parent directory?
The Code lists all users of my computer and defines the homedirectories.
Each user has an own directory, which must not be deleted!
Dim o As DirectoryEntry
Dim c As DirectoryEntries
o = New DirectoryEntry(LDAPusers)
c = o.Children
Dim snc As SchemaNameCollection
snc = c.SchemaFilter
snc.Add("User")
For Each o In c
Dim homedir = "G:\test\" & o.Name
Dim d As DirectoryInfo
d = New DirectoryInfo(homedir)
On Error Resume Next
d.Delete(True)
Next
THX
Jan Wrage