Created
February 9, 2022 11:28
-
-
Save gioxx/81d66dc11de393fa5b836855c3156985 to your computer and use it in GitHub Desktop.
Uno script che permette di pulire la cartella Patch di ManageEngine ServiceDesk Plus (Aggiornato al 2022)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'GSolone 2019 | |
' ult.mod. 9/2/22: integro le eccezioni per cartelle e file da escludere dalla pulizia | |
' Credits: | |
' https://www.experts-exchange.com/questions/23543652/VBScript-to-delete-all-files-and-folders-in-a-directory.html | |
' https://www.automateexcel.com/vba/getfolder-getfile/ | |
' https://superuser.com/a/1127074 | |
strFolder = "C:\ManageEngine\ServiceDesk\Patch" | |
intDays = 0 | |
' Non toccare nulla oltre questa riga / Don't modify anything after this line | |
Dim fileException, folderException, i | |
Dim lockedFolders(10), lockedFiles(10) | |
Set objFSO = CreateObject("Scripting.FileSystemObject") | |
Set objFolders = objFSO.GetFolder(strFolder) | |
objToday = Now() | |
objPastDate = DateAdd("d", intDays*-1, objToday) | |
lockedFolders(0) = "logs" | |
lockedFolders(1) = "tmp" | |
lockedFiles(0) = "inf.xml" | |
lockedFiles(1) = "specs.xml" | |
Recurse objFolders | |
Sub recurse(ByRef objFolders) | |
Set objSubFolders = objFolders.SubFolders | |
Set objFiles = objFolders.Files | |
For Each File In objFiles | |
'MsgBox("Debug: " & File.Name) | |
fileException = False | |
For i = LBound(lockedFiles) to UBound(lockedFiles) | |
If lCase(File.Name) = lCase(lockedFiles(i)) Then | |
fileException = True | |
Exit For | |
End If | |
Next | |
If Not fileException Then | |
If File.DateLastModified < objPastDate Then | |
On Error Resume Next | |
File.Delete | |
End If | |
Else | |
'MsgBox("Exception found: " & File.Name) | |
End If | |
Next | |
For Each Folder In objSubFolders | |
'MsgBox("Debug: " & Folder.Name) | |
folderException = False | |
For i = LBound(lockedFolders) to UBound(lockedFolders) | |
If lCase(Folder.Name) = lCase(lockedFolders(i)) Then | |
folderException = True | |
Exit For | |
End If | |
Next | |
If Not folderException Then | |
If Folder.DateLastModified < objPastDate Then | |
On Error Resume Next | |
objFSO.DeleteFolder Folder.Path, True | |
Else | |
recurse Folder | |
End If | |
Else | |
'MsgBox("Exception found: " & Folder.Name) | |
End If | |
Next | |
Set objSubFolders = Nothing | |
Set objFiles = Nothing | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment