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
| Function ConvertSize(Size)
Do While InStr(Size,",")
CommaLocate = InStr(Size,",")
Size = Mid(Size,1,CommaLocate - 1) & _
Mid(Size,CommaLocate + 1,Len(Size) - CommaLocate)
Loop
Suffix = " Bytes"
If Size >= 1024 Then suffix = " KB"
If Size >= 1048576 Then suffix = " MB"
If Size >= 1073741824 Then suffix = " GB"
If Size >= 1099511627776 Then suffix = " TB"
Select Case Suffix
Case " KB" Size = Round(Size / 1024, 2)
Case " MB" Size = Round(Size / 1048576, 2)
Case " GB" Size = Round(Size / 1073741824, 2)
Case " TB" Size = Round(Size / 1099511627776, 2)
End Select
ConvertSize = Size & Suffix
End Function
Function CreateAfile(resumeFile)
Dim fso, MyFile 'fso pour File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(resumeFile, True)
End Function
Function WriteText(myFile,myText)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, f, ts
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(MyFile)
Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
ts.WriteLine myText
ts.Close
End Function
Dim fs
Dim outputFile
outputFile = "C:\dirSize" & Year(Now) & Month(Now) & Day(Now) & ".csv"
checkDir = "C:\Utilisateurs"
CreateAfile(outputFile)
Set fs = CreateObject("Scripting.FileSystemObject")
Call ListFolderContents(checkDir)
Set fs = Nothing
Sub ListFolderContents(path)
set folder = fs.GetFolder(path)
If fs.FolderExists(folder) Then
Set oFld = fs.GetFolder(folder)
wscript.echo folder.path & " - " & ConvertSize(oFld.Size)
If oFld.Size > 62914560 And folder.path <> checkDir Then
WriteText OutputFile, folder.path & ";" & Replace(folder.path, checkDir, "") & ";" & ConvertSize(oFld.Size) & ";" & oFld.Subfolders.count & ";" & oFld.Files.Count
End If
End If
For each item in folder.SubFolders
ListFolderContents(item.Path)
Next
set folder = Nothing
End Sub |
Partager