Test si un lecteur (drive) existe et s'il est accessible.
Cette fonction permet également de tester si un drive réseau non mappé (eg: 'serveurdirectory')est accessible.
Cette fonction utilise la librairie SCRIPTING de Microsoft (SCRRUN.DLL) elle peut donc être utilisée sous VB6 et en ASP.
Source / Exemple :
'********************************************************************************************
' 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