Hello,
I'm very new to scripting. I was wondering if someone could help me with a script to delete all subfolders and files within a specified folder. I have a script below which is made up of two scripts that I took from a couple of people. It works, but I have lines in there that are not necessary because I do not need to save anything from the folder. The first script erases files from the specified folder, but does not erase the subfolders or files within those subfolders. The second part erases the subfolders and files within those, but not any files that are within the specified folder.
Set fso=CreateObject("Scripting.FileSystemObject")
CleanPath="C:\Test\"
For Each file In fso.GetFolder(CleanPath).Files
file.attributes = file.attributes And Not 1
file.delete
Next
---------------End first Part---------------
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder("C:\Test\")
arrFolders = Array()
For Each oFolder In oFolder.SubFolders
' Note : Only use *lowercase* letters in the folder names below:
If Not LCase(oFolder.Name) = "foldera" _
And Not LCase(oFolder.Name) = "folderb" _
And Not LCase(oFolder.Name) = "folderc" Then
intCount = UBound(arrFolders) + 1
ReDim Preserve arrFolders(intCount)
arrFolders(intCount) = oFolder.Path
End If
Next
For n = 0 To UBound(arrFolders)
fso.DeleteFolder arrFolders(n), True
Next
---------------
Can someone help refine this script so that it is neater. The person the script was originally created for wanted to keep certain subfolders. Since I don't, I don't need those extra lines of code.
Thanks
Spike