VBS Removing files within a directory using FileSystemObject with exceptions?
I work with the rather finnicky Oracle Business Intelligence software and we often have issues that entail, clearing out specific data on users systems, and then synchronizing with the server to pull down the data again. I've got a vbs script that I'm working on that removes key directories, and renames others and stops services etc.
Where I'm stuck is on one specific directory. Using FileSystemObject, what would be the easiest way to remove every single file within a directory with the exception of a singl开发者_如何学Ce folder?
So, for this specific example, I have C:\OracleBIData\sync\config
Where I want to delete everything inside of the "sync" directory, with the exception of the config directory. Any takers?
Snippet:
Option explicit
Const folderspec = "C:\OracleBIData\sync"
Const excludeFolder = "C:\OracleBIData\sync\config"
deleteSubFolders CreateObject("Scripting.FileSystemObject").GetFolder(folderspec), excludeFolder
Public Sub deleteSubFolders(byRef MyFolder, exclFolder)
Dim sf
For Each sf in MyFolder.SubFolders
If not (lCase(sf.Path) = lCase(exclFolder)) Then
deleteSubFolders sf, exclFolder
sf.Delete
End If
Next
End Sub
It will not delete folders under the excludeFolder.
Brute force is all I can think of.
Walk through the directory item but item and delete it if it is not config. Or if this directory has lots and lots and lots of files, first run through deleting a*., b.*, d*.* 25 times, and then walk through the rest of the items.
精彩评论