Mega Code Archive

 
Categories / VisualBasic Script / File Path
 

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