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
| Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strComputer, strPath, Debug
strComputer = "."
strDrive = "E:"
strPath = "applic\import"
Debug=False 'Debug=True pour afficher les msgbox, les fichiers ne seront pas supprimés
'Debug=False pas de msgbox, les fichiers seront supprimés
objStartFolder = strDrive & "\" & strPath
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
If colFiles.Count <> 0 Then
For Each objFile in colFiles
dtDiffFile = DateDiff("d", Now, fnConversionDate(objFile.LastModified))
If dtDiffFile =< -5 Then ' 5 pour nombre de jours
If Debug=True Then _
MsgBox "Le fichier " &vbLf& objFile.Drive &vbLf& _
objFile.Path & objFile.FileName & _
"." & objfile.Extension &vbLf& " sera supprimé car modifié le " & _
fnConversionDate(objFile.LastModified) &vbLf& _
Now & " - " & fnConversionDate(objFile.LastModified) & " = " & _
dtDiffFile,vbCritical,"Verif DELETE=OUI"
If Debug=False Then objFile.Delete(objFile.Path & objFile.FileName)
Else
If Debug=True Then _
MsgBox "Le fichier " &vbLf& objFile.Drive & _
objFile.Path & objFile.FileName & _
"." & objfile.Extension &vbLf& " ne sera pas supprimé car modifié le " & _
fnConversionDate(objFile.LastModified) &vbLf& _
Now & " - " & fnConversionDate(objFile.LastModified) & " = " & _
dtDiffFile,vbInformation,"Verif DELETE=NON"
End If
Next
Else
If Debug=True Then MsgBox "le répertoire " & strPath & " n'existe pas"
End If
Set objWMIService = Nothing
Set colFiles = Nothing
Function fnConversionDate(strDateUTC)
fnConversionDate = Mid(strDateUTC, 7, 2) & "/" & Mid(strDateUTC, 5, 2) & "/" & _
Left(strDateUTC, 4) & " " & Mid(strDateUTC, 9, 2) & ":" & _
Mid(strDateUTC, 11, 2) & ":" & Mid(strDateUTC, 13, 2)
End Function |
Partager