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
|
option explicit
'Variables
Dim Racine
Dim Size, NbFic
Dim strComputer, strNewPathCourant, strPathCourant
Dim objWMIService, objRep, objRep2, objFic
Dim colSousRep, colSousRep2,colFic
Dim arrRepPath
Dim i
'Initialisation
NbFic = 0
' Choix du répertoire/volume à auditer
Racine = InputBox("Nom du volume ou sous-répertoire racine ?","Question")
' Recherche des fichiers et sous-répertoire
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colSousRep = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & Racine & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
' Ajout d'un "\" a chaque "\" du PATH courant
arrRepPath = Split(Racine, "\")
strNewPathCourant = ""
For i = 1 to Ubound(arrRepPath)
strNewPathCourant = strNewPathCourant & "\\" & arrRepPath(i)
Next
strPathCourant = strNewPathCourant & "\\"
' Traitement des fichiers du répertoire Racine
Set colFic = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPathCourant & "'")
For Each objFic in colFic
Size = objFic.filesize
If Size > 10000000 Then
NbFic = NbFic + 1
End If
Next
'Appel de la fonction de parcours récursif
For Each objRep in colSousRep
ShowSubFolders Racine
Next
Sub ShowSubFolders(Racine)
' Recherche des fichiers et sous-répertoires
Set colSousRep2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & Racine & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objRep2 in colSousRep2
Racine = objRep2.Name
arrRepPath = Split(Racine, "\")
strNewPathCourant = ""
For i = 1 to Ubound(arrRepPath)
strNewPathCourant = strNewPathCourant & "\\" & arrRepPath(i)
Next
strPathCourant = strNewPathCourant & "\\"
Set colFic = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPathCourant & "'")
For Each objFic in colFic
Size = objFic.filesize
If Size > 10000000 Then
NbFic = NbFic + 1
End If
Next
ShowSubFolders Racine
Next
End Sub
WScript.Echo "Nombre de fichiers : " & NbFic |
Partager