首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

帮忙哦,用VB检测到指定 "卷标" 的挪动U盘.

2012-12-17 
帮忙哦,用VB检测到指定 卷标 的移动U盘...............我想实现以下功能:用VB检测到指定 卷标 的移动U

帮忙哦,用VB检测到指定 "卷标" 的移动U盘...............
我想实现以下功能:

用VB检测到指定 "卷标" 的移动U盘就提示找到,否则就提示未找到
然后再检测以上指定卷标的移动U盘里的a.txt里的内容,如果内容等于123就提示对,否则提示错

希望各位能贴出"完整"的代码哦
我没有分给你们哦,里面分空空的。谢谢各位啦
[解决办法]

Private Declare Function GetDriveType Lib "kernel32 " Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Sub Command1_Click()
    Dim i     As Long
    For i = Asc("C ") To Asc("Z ")
        If GetDriveType(Chr(i) + ": ") = 2 Then Debug.Print "现有U盘:   " & Chr(i)
    Next i
End Sub

这是枚举U盘的


Private Sub Command1_Click()
Dim fso As Object, drv As Object
Dim dr As Long, fn As String
fn = "123.txt"                 '指定文件
Set fso = CreateObject("scripting.filesystemobject")
For dr = 99 To 122
If fso.driveexists(Chr(dr) & ":") Then
    Set drv = fso.GetDrive(Chr(dr) & ":")
    If drv.drivetype = 1 Then
        Print Chr(dr) & "盘 "; drv.volumename; " ";
        If Dir(Chr(dr) & ":" & fn) = "" Then
            Print "未找到指定文件"
        Else
            Print "找到了指定文件"
        End If
    End If
End If
Next
Set drv = Nothing
Set fso = Nothing
End Sub
自己再结合一下吧

热点排行