Bonjour a tous je cherche a cree un script VBS pour Effaces les fichier et S/dossier qui date de plus de 15Jr dans un repertoire donné

jai trouvé un script qui se rapproche de ce que je veut mais il est aleatoire et n'efface pas les S/dossier et les fichier dans les S/dossier
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
'****************************************************************
' Script permettant D 'effacer les fichiers Qui date de plus de 15 jours
' Avec interface Graphique
'
'*****************************************************************
 
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2" )
Set objFSO = CreateObject("Scripting.FileSystemObject" )
Set objShell = CreateObject("Shell.Application" )        
Set objFolder = objShell.BrowseForFolder _
       (WINDOW_HANDLE, "Selectionner le dossier à traiter :", NO_OPTIONS, "." )
Set objFolderItem = objFolder.Self
strFolderName = objFolderItem.Path
 
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)>15 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)>15 then
        'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified
        objFile.delete
 
      end if
 
    Next
 
    GetSubFolders strFolderName
  Next
End Sub
merci d'avance de votre aide je suis un pauvre debutant qui cale rien ^^