Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete all folders within mainfolder 2

Status
Not open for further replies.

din2005

Programmer
Mar 22, 2005
162
GB
Hi all

I am trying to use this code

fso.DeleteFolder "X:\pub\Snapshots\"

and i don't think it deletes. What i want to do is delete all folders within the Snapshots directory. If i remove the "\" at the end of snapshots it will delete the snapshots directory... but i don't want it to delete the snapshots directory only folders within that directory.

any suggestions
 
Sub ClearFolders(strFolderPath As String)

Dim fso As Object
Dim myFldr As Object
Dim subFldrs As Object
Dim subFldr As Object

Set fso = CreateObject("Scripting.FileSystemObject")
Set myFldr = fso.GetFolder(strFolderPath)
Set subFldrs = myFldr.subFolders 'Here is the trick

'Just a For Each loop
For Each subFldr In subFldrs
fso.DeleteFolder subFldr, True
Next

'Clean up
Set subFldrs = Nothing
Set myFldr = Nothing
Set fso = Nothing

End Sub
 
And what about this ?
fso.DeleteFolder "X:\pub\Snapshots\[!]*[/!]", True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top