Bonjour,
Je souhaitres une aide svp pour ce script, que j'ai trouvé, ca sert à éffacer automatiquement des fichiers dans un dossier, selon une date de modification qu'on choisie.
Ce script fonctionne parfetement, mais seulement je voudrais le modifier, afin de supprimer des fichiers non pas selon leur date, mais plutôt l'Heure de modification...
C'est possible ca ??
J'ai beaucoup cherché sur ce site un script du genre, même sur google, mais sans succés....
Merci beaucoup pour votre aide, mes connaissance sont vraiment limitées.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
strFolderName = "C:\test"
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
'Wscript.Echo strFolderName
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "'")
For Each objFile in colFiles
Set objReadOnlyFile = objFSO.GetFile(objFile.Name)
'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified
if DateDiff("d",objReadOnlyFile.DateLastModified ,Date)>10 then
objFile.delete
end if
Next
For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next
Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
'Wscript.Echo
'Wscript.Echo objFolder2.Name
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "'")
For Each objFile in colFiles
Set objReadOnlyFile = objFSO.GetFile(objFile.Name)
if DateDiff("d",objReadOnlyFile.DateLastModified ,Date)>10 then
'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified
objFile.delete
end if
Next
GetSubFolders strFolderName
Next
End Sub