Thursday, May 13, 2010

File System Object Vs Drives

Total Number of Drives
Drive Information
Drive Name of a specified file path
Drive is Ready or Not

'Total Number of Drives in your System
Set FSO = CreateObject("Scripting.FileSystemObject")
Set DriveCollection= FSO.Drives
'A collection of drive objects
MsgBox("Total Number of Drives available in your system: "&DriveCollection.Count)

'Drive Information in your System
Set FSO = CreateObject("Scripting.FileSystemObject")
intDrive = 0
For Each Driver in FSO.Drives
Msgbox "Name of the Drive :"&Driver.DriveLetter
Select Case Driver.DriveType
Case 0: strDriveType = "Drive type cannot be determined"
Case 1: strDriveType = "Removable Drive"
Case 2: strDriveType = "Fixed Drive"
Case 3: strDriveType = "CD-ROM"
Case 4: strDriveType = "RAM Disk"
End Select
msgbox "Type of the Drive : "&strDriveType
If(Driver.DriveType = 2)Then
msgbox "Total Size of the Specified Drive: "&Driver.Totalsize
msgbox "Free Space available in the Drive: "&Driver.FreeSpace
msgbox "Available Space in the Drive: "&DriverAvailableSpace
msgbox "File System of the specified Drive: "&Driver.FileSystem
'Available File Systems are FAT, NTFS and CDFS
msgbox "Serial Number of the specified Drive: "&Driver.SerialNumber
msgbox "Share Name of the specified Drive: "&Driver.ShareName
msgbox "Volume Name of the specified Drive: "&Driver.VolumeName
End If
intDrive = intDrive + 1
Next


'Drive Name of a specified file path
DrvPath = "D:\debugnew.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set GetDriveInfo = fso.GetDriveName(drvPath)
Msgbox ("Name of the Drive :"&GetDriveInfo)


'Drive is Ready or Not
DrvPath = "D:\debugnew.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set GetDriveInfo = fso.GetDrive(fso.GetDriveName(drvPath))
If GetDriveInfo.IsReady Then
Msgbox "Drive is Ready"
Else
Msgbox "Drive is Not Ready"
End If

3 comments: