Bonjour,

Je dois faire le ménage sur un serveur de fichiers comprenant aujourd'hui 2 To de données.
Je me suis lancé dans un script en VBs me permettant de supprimer tous les fichiers dont la date de dernier accès est antérieur à un an.

Voici le script
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
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")
 
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.DateLastAccessed ,Date)>365 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
        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.DateLastAccessed ,Date)>365 then
            objFile.delete
 
          end if
 
        Next
 
        GetSubFolders strFolderName
    Next
End Sub


Mais comme dans toutes bonne société, il y a toujours des utilisateurs souhaitant être des exceptions, et dont il ne faut surtout pas faire de ménage dans les dossiers leurs appartenant.
J'ai donc une liste de répertoires et sous-répertoires qui ne doivent pas être pris en compte par ce script.

Exemple :
D:\Studio\Images\ A nettoyer
D:\Studio\Images\EMD\ A ne pas toucher
D:\Studio\Site_V2\ A ne pas toucher
...

Quelqu'un a t'il une aide à m'apporter ?
Merci pour vos futurs réponses.