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 86 87
|
Public Class Form1
Private Declare Function GetDiskFreeSpaceEx _
Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
( _
ByVal lpDirectoryName As String, _
ByVal lpFreeBytesAvailableToCaller As Decimal, _
ByVal lpTotalNumberOfBytes As Decimal, _
ByVal lpTotalNumberOfFreeBytes As Decimal _
) As Long
Private Sub Form_Load()
Dim fso As FileSystemObject
Dim Drv As Drive, DrvName As String
Dim d As Drive
Dim dc As Drives
Dim st As String
Dim TotalBytes, FreeBytes As Decimal
Dim Espace_Libre As String
Dim Espace_Total As String
Dim Pourcentage_Libre As Long
fso = CreateObject("Scripting.FileSystemObject")
dc = fso.Drives
For Each d In dc
Drv = fso.GetDrive(Mid(d, 1, 2))
If Drv.DriveType = Remote Then
DrvName = Drv.Path & "\"
st = DrvName & " " & Drv.ShareName
Pourcentage_Libre = 0
Espace_Libre = ""
Espace_Total = ""
If Drv.IsReady Then
GetDiskFreeSpaceEx(CStr(Drv) & "\", 0, TotalBytes, FreeBytes)
Pourcentage_Libre = Int(FreeBytes * 10000 / (TotalBytes * 10000) * 100)
If FreeBytes * 10000 > 1024 ^ 3 Then
Espace_Libre = FormatNumber((FreeBytes * 10000 / 1024 ^ 3), -1) & " Go"
Else
If FreeBytes * 10000 > 1024 ^ 2 Then
Espace_Libre = FormatNumber((FreeBytes * 10000 / 1024 ^ 2), -1) & " Mo"
Else
If FreeBytes * 10000 > 1024 Then
Espace_Libre = FormatNumber((FreeBytes * 10000 / 1024), -1) & " Ko"
End If
End If
End If
If TotalBytes * 10000 > 1024 ^ 3 Then
Espace_Total = FormatNumber((TotalBytes * 10000 / 1024 ^ 3), -1) & " Go"
Else
If TotalBytes * 10000 > 1024 ^ 2 Then
Espace_Total = FormatNumber((TotalBytes * 10000 / 1024 ^ 2), -1) & " Mo"
Else
If TotalBytes * 10000 > 1024 Then
Espace_Total = FormatNumber((TotalBytes * 10000 / 1024), -1) & " Ko"
End If
End If
End If
End If
If Pourcentage_Libre <> 0 Then
st = st & " - Libre " & Espace_Libre & " (" & Pourcentage_Libre & "%)"
st = st & " - Total " & Espace_Total
End If
End If
Next
MsgBox(st)
fso = Nothing
End Sub
End Class |
Partager