Get Drive Information : Drive « File Path « VBA / Excel / Access / Word






Get Drive Information

 
Declare Function abGetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Declare Function abGetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long

'The GetDriveInfo Procedure
Sub GetDriveInfo()
   Dim intDrive As Integer
   Dim strDriveLetter As String
   Dim strDriveType As String
   Dim strSpaceFree As String

   'Loop through all drives
   For intDrive = 65 To 90 'A through Z
     strDriveLetter = (Chr(intDrive) & ":\")
     'Get Drive Type
     strDriveType = TypeOfDrive(strDriveLetter)
     'Get Space Free
     strSpaceFree = NumberOfBytesFree(strDriveLetter)
     Debug.Print Left(strDriveLetter, 2) & _
         " - " & strDriveType & _
         IIf(strDriveType <> "Drive Doesn't Exist", _
            strSpaceFree, "") & _
         vbCrLf
   Next intDrive

End Sub

 








Related examples in the same category

1.The TypeOfDrive Function
2.The NumberOfBytesFree Function
3.Returns the number of free bytes for a drive
4.Returns the total storage capacity for a drive
5.Returns a string that describes the drive type
6.Returns True if a specified drive letter exists
7.Returns the number of drives
8.Returns the drive letter using an index
9.Display Drive information