如何用VB找盘符?请教高手!
用VB找盘符希望能给出代码例子是:如果G盘有A文件,读取如果没有G盘A文件,继续搜索H盘是否有A文件如果有读取,没有继续搜索I盘,搜索到则读取。最主要是寻找盘符的代码,读...
用VB找盘符 希望能给出代码
例子是:
如果G盘有A文件,读取
如果没有G盘A文件,继续搜索H盘是否有A文件
如果有读取,没有继续搜索I盘,搜索到则读取。
最主要是寻找盘符的代码,读取代码可以掠过。
哪位高手可以帮下小弟~感激不尽 谢谢! 展开
例子是:
如果G盘有A文件,读取
如果没有G盘A文件,继续搜索H盘是否有A文件
如果有读取,没有继续搜索I盘,搜索到则读取。
最主要是寻找盘符的代码,读取代码可以掠过。
哪位高手可以帮下小弟~感激不尽 谢谢! 展开
1个回答
展开全部
下面是代码,getdrive调用后返回机器上所有盘符
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Function GetDriveName(ByVal nType As Long)
Select Case nType
Case 1
GetDriveName = "目录不存在"
Case DRIVE_REMOVABLE
GetDriveName = "软盘"
Case DRIVE_FIXED
GetDriveName = "硬盘"
Case DRIVE_REMOTE
GetDriveName = "映射磁盘"
Case DRIVE_CDROM
GetDriveName = "光驱"
Case DRIVE_RAMDISK
GetDriveName = "RAM Disk"
Case Else
GetDriveName = "无法判断"
End Select
End Function
Public Function getdrive()
Dim nType As Long, s As String, sDrive As String
Dim pos As Integer
s = String(256, Chr(0))
GetLogicalDriveStrings Len(s), s
Do
pos = InStr(s, Chr(0))
sDrive = Left(s, pos - 1)
If Len(sDrive) = 0 Then Exit Do
s = Mid(s, pos + 1)
nType = GetDriveType(sDrive)
d = d & GetDriveName(nType) & Left(sDrive, 2) & vbCrLf
Loop Until pos <= 0
getdrive = d
End Function
Private Sub Command1_Click()
MsgBox getdrive
End Sub
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Function GetDriveName(ByVal nType As Long)
Select Case nType
Case 1
GetDriveName = "目录不存在"
Case DRIVE_REMOVABLE
GetDriveName = "软盘"
Case DRIVE_FIXED
GetDriveName = "硬盘"
Case DRIVE_REMOTE
GetDriveName = "映射磁盘"
Case DRIVE_CDROM
GetDriveName = "光驱"
Case DRIVE_RAMDISK
GetDriveName = "RAM Disk"
Case Else
GetDriveName = "无法判断"
End Select
End Function
Public Function getdrive()
Dim nType As Long, s As String, sDrive As String
Dim pos As Integer
s = String(256, Chr(0))
GetLogicalDriveStrings Len(s), s
Do
pos = InStr(s, Chr(0))
sDrive = Left(s, pos - 1)
If Len(sDrive) = 0 Then Exit Do
s = Mid(s, pos + 1)
nType = GetDriveType(sDrive)
d = d & GetDriveName(nType) & Left(sDrive, 2) & vbCrLf
Loop Until pos <= 0
getdrive = d
End Function
Private Sub Command1_Click()
MsgBox getdrive
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询