【已解决】DriveGetType 怎么同时查看几个驱动器?
本帖最后由 leibin0121 于 2011-9-19 19:50 编辑DriveGetType ("d:\")是查看D盘,如果我想同时查看g到z的驱动器是不是固定盘,要怎么写呢?求解答!$var = DriveGetType("d:\" )
If$var ="fixed" Then
MsgBox(16,"Warning"," 固定磁盘! ")
EndIf
If $var= "ramdisk" Or "removable"Or"cdrom" Then
MsgBox(16,"Warning"," 非本地磁盘! ")
EndIf
非常感谢 lixiaolong的热心帮助,感激不尽! 本帖最后由 lixiaolong 于 2011-9-17 23:22 编辑
#include <Array.au3>
Local $avArray
For $i = 67 To 90 ; 67 = C, 90 = Z
$var = DriveGetType(Chr($i) & ":\")
If $var Then
If $var = "Fixed" Then
$var = "固定磁盘"
Else
$var = "非本地磁盘!"
EndIf
Else
$var = "NoDriveType"
EndIf
_ArrayAdd($avArray, Chr($i) & ":\ " & $var)
Next
_ArrayDisplay($avArray, "")
$avArray = C:\
$avArray = D:\
$avArray = E:\
$avArray = F:\
$avArray = G:\
$avArray = H:\
$avArray = I:\
$avArray = J:\
$avArray = K:\
$avArray = L:\
$avArray = M:\
$avArray = N:\
$avArray = O:\
$avArray = P:\
$avArray = Q:\
$avArray = R:\
$avArray = S:\
$avArray = T:\
$avArray = U:\
$avArray = V:\
$avArray = W:\
$avArray = X:\
$avArray = Y:\
$avArray = Z:\ 回复 2# lixiaolong
非常感谢这位大哥的热心帮助!学到了新东西,感激不尽!! 回复 2# lixiaolong
为什么这样没用啊?
Local $i
For $i = 67 To 90
$var = DriveGetType(Chr($i) & ":\")
If $var = "Fixed" And "cdrom" Then
MsgBox(16,"Warning"," 固定磁盘和光驱")
EndIf
If $var = "RAMDisk" And "removable" Then
MsgBox(16,"Warning","移动磁盘")
EndIf
我想检测C到Z的驱动器状态,然后在执行对应操作,请大哥指点一二。 回复 4# leibin0121
指定的驱动器不存在,返回 ""(空白).
你设了条件,并没有返回空白时的处理.
你的代码只能检查"Fixed"(固定的)、 "RAMDisk"(内存盘).
仔细看看你自己的代码.
Local $i
For $i = 67 To 90
$var = DriveGetType(Chr($i) & ":\")
If $var = "Fixed" And "cdrom" Then
MsgBox(16,"Warning"," 固定磁盘和光驱")
EndIf
If $var = "RAMDisk" And "removable" Then
MsgBox(16,"Warning","移动磁盘")
Else
EndIf
Next
你的代码是这样.如果 $var的值为 "Fixed"
MsgBox(16,"Warning"," 固定磁盘和光驱")
EndIf
如果 $var的值为 "RAMDisk"
MsgBox(16,"Warning","移动磁盘")
EndIf你是想写成这样吧?如果 $var的值为 "Fixed" 或者 $var的值为 "cdrom"
弹出消息框 MsgBox(16,"Warning"," 固定磁盘和光驱")
如果 $var的值为 "RAMDisk" 或者 $var的值为 "removable"
弹出消息框 MsgBox(16,"Warning","移动磁盘")这样写法是不对的.
If $var = "Fixed" And "cdrom" Then
那么因该是这样写
Local $i
For $i = 67 To 90
$var = DriveGetType(Chr($i) & ":\")
If $var = "Fixed" Or $var = "cdrom" Then
MsgBox(16,"Warning"," 固定磁盘和光驱")
EndIf
If $var = "RAMDisk" Or $var = "removable" Then
MsgBox(16,"Warning","移动磁盘")
Else
EndIf
Next
你想检测C到Z的驱动器状态,那就再加个判断.
If $var = "Unknown" Then
MsgBox(16, "Warning", "???")
EndIf
If $var = "" Then
MsgBox(16, "Warning", "???")
EndIf
遇到这样问题时,看看帮助查一下各个函数的意思,你把它翻译成中文,自然就明白哪里错了. 回复 5# lixiaolong
终于等到你了 呵呵,or是不是能理解成"或者"?and是不是能理解成"和"啊? 本帖最后由 lixiaolong 于 2011-9-19 20:47 编辑
回复 6# leibin0121
Or = 或者
And 应该是 "而且"吧,帮助里也是而且.
页:
[1]