- '********************************************************************************************
- ' Name : xIsDriveReady
- ' Purpose : Test if a drive is exist and is ready to be used
- ' Syntax : xIsDriveReady(DriveName)
- ' Parameters : DriveName : The drive name or full path.
- ' eg: "c", "c:", "c:windows", or "my computermy directory"
- ' Return : True is the drive is ready, False if it is not
- '********************************************************************************************
- Public Function xIsDriveReady(ByVal DriveName As String) As Boolean
- Dim objFileSys As Object
- Dim objDrive As Object
- Dim strDrive As String
-
- On Error GoTo DriveError
-
- If Left(DriveName, 1) = "" Then
- strDrive = DriveName ' If it is a network path, then let it as it is.
- Else
- strDrive = Left(DriveName, 1) & ":" ' Create the drive name, to be sure it is in the correct format. eg: "C:"
- End If
- Set objFileSys = CreateObject("Scripting.FileSystemObject") ' Create the filesystem object
- Set objDrive = objFileSys.GetDrive(CStr(strDrive))
- If objFileSys.DriveExists(strDrive) Then ' Test if the drive exist
- xIsDriveReady = objDrive.IsReady ' Test if it is ready to be used
- Else
- xIsDriveReady = False
- End If
- Exit Function
-
- DriveError:
- xIsDriveReady = False
- End Function
'********************************************************************************************
' Name : xIsDriveReady
' Purpose : Test if a drive is exist and is ready to be used
' Syntax : xIsDriveReady(DriveName)
' Parameters : DriveName : The drive name or full path.
' eg: "c", "c:", "c:windows", or "my computermy directory"
' Return : True is the drive is ready, False if it is not
'********************************************************************************************
Public Function xIsDriveReady(ByVal DriveName As String) As Boolean
Dim objFileSys As Object
Dim objDrive As Object
Dim strDrive As String
On Error GoTo DriveError
If Left(DriveName, 1) = "" Then
strDrive = DriveName ' If it is a network path, then let it as it is.
Else
strDrive = Left(DriveName, 1) & ":" ' Create the drive name, to be sure it is in the correct format. eg: "C:"
End If
Set objFileSys = CreateObject("Scripting.FileSystemObject") ' Create the filesystem object
Set objDrive = objFileSys.GetDrive(CStr(strDrive))
If objFileSys.DriveExists(strDrive) Then ' Test if the drive exist
xIsDriveReady = objDrive.IsReady ' Test if it is ready to be used
Else
xIsDriveReady = False
End If
Exit Function
DriveError:
xIsDriveReady = False
End Function