1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| '*************
' VARIABLES
'*************
'On Error Resume Next
ScriptName = "Purgefic.wsf"
PathINI = PathINI & "PURGEFIC.ini"
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
'*************
' MAIN
'*************
log_writeLine ScriptName, "PURGEFIC_DEBUT", "0", "0", "Démarrage du script " & ScriptName & ""
If (FileExists (PathINI) = "1") Then
log_writeLine ScriptName, "PURGEFIC_ERROR", "0", "2", "Le fichier de paramètres INI n'existe pas"
WScript.Quit
'pouvons nous tesdter plusieurs sections ex = (PathINI, "PURGE", "DELETE")
End If
section = "PURGE"
incr = 1
Do While (ini_testSection (PathINI, section) = "1")
list_purge = ini_readValue (PathINI, section, "listpurge")
ret = ini_readValue (PathINI, section, "retention")
list_svc = ini_readValue (PathINI, section, "svc")
STOP_SVC list_svc, computer
Do While list_purge <> ""
pos = Instr (list_purge, ";")
scr = ""
Select Case pos
case "0"
scr = Trim (list_purge)
list_purge = ""
case "1"
list_purge = Trim (Mid (list_purge, pos+1))
case else
scr = Trim (Left (list_purge, pos-1))
list_purge = Trim (Mid (list_purge, pos+1))
End Select
If (PathExists (scr) = "0") Then
Set Afolder=FSO.GetFolder(scr)
Set TheFiles = Afolder.Files
For Each AFile In TheFiles
If DateDiff("d",(FSO.GetFile(AFile)).datecreated,Date) > Int(ret) Then
Name = AFile.Name
AFile.Delete
log_writeLine ScriptName, "PURGEFIC_INFO", "0", "0", "Fichier " & Name & " supprimé"
End If
Next
ElseIf FileExists(scr) = "0" Then
Set Afile=FSO.GetFile(scr)
If DateDiff("d",Afile.datecreated,Date) > Int(ret_delete) Then
Name = Afile.Name
Afile.Delete
log_writeLine ScriptName, "PURGELOG_INFO", "0", "0", "Fichier " & Name & " supprimé"
End If
Else
log_writeLine ScriptName, "PURGEFIC_WARNING", "0", "1", "Le Dossier ou fichier à purger n'existe pas : " & scr
End If
Loop
START_SVC list_svc, computer
incr = incr+1
section = section & incr
Loop
If Err <> 0 Then
log_writeLine ScriptName, "VBS_ERROR", "0", "2", "ERREUR: "& Err.Number &" "& Err.Description &""
Err.Clear
End If
log_writeLine ScriptName, "PURGEFIC_FIN", "0", "0", "Fin du script " & ScriptName & ""
'THE END
</script>
</job> |
Partager