本帖最后由 pusofalse 于 2010-2-5 01:09 编辑
方法多如牛毛。 - -|||#include <Array.au3>
$aEmpty = _GetEmptyDrives1()
_Arraydisplay($aEmpty)
$aEmpty = _GetEmptyDrives2()
_Arraydisplay($aEmpty)
$aEmpty = _GetEmptyDrives3()
_Arraydisplay($aEmpty)
$aEmpty = _GetEmptyDrives4()
_Arraydisplay($aEmpty)
$aEmpty = _GetEmptyDrives5()
_Arraydisplay($aEmpty)
#include <WinAPI.au3>
$aEmpty = _GetEmptyDrives6()
_Arraydisplay($aEmpty)
Func _GetEmptyDrives1()
Local $sDrives, $aDrive, $sResult
$aDrive = DriveGetDrive("All")
For $i = 1 To $aDrive[0]
$sDrives &= $aDrive[$i]
Next
For $i = 1 to 26
$sResult &= Chr(96 + $i)
Next
$sResult = StringRegExpReplace($sResult, "[" & $sDrives & "]", "")
Return StringSplit($sResult, "")
EndFunc ;==>_GetEmptyDrives1
Func _GetEmptyDrives2()
Local $aDrive, $sDrive, $sResult
$aDrive = DriveGetDrive("All")
For $i = 1 To $aDrive[0]
$sDrive &= $aDrive[$i]
Next
For $i = 1 To 26
If Not StringInStr($sDrive, Chr(96 + $i)) Then
$sResult &= Chr(96 + $i)
EndIf
Next
Return StringSplit($sResult, "")
EndFunc ;==>_GetEmptyDrives2
Func _GetEmptyDrives3()
Local $aDrive, $sDrive, $sResult
$aDrive = DriveGetDrive("All")
For $ii = 1 To $aDrive[0]
Assign($aDrive[$ii], 0)
Next
For $ii = 1 To 26
If Not IsDeclared(Chr(96 + $ii) & ":") Then
$sResult &= Chr(96 + $ii)
EndIf
Next
Return StringSplit($sResult, "")
EndFunc ;==>_GetEmptyDrives3
Func _GetEmptyDrives4() ; ?? Can you find BUGs on this function?
Local $sResult, $sDrive
$aDrive = DriveGetDrive("All")
For $i = 1 To 26
$sDrive &= Chr($i + 96)
Next
$sResult = "ab" & StringTrimLeft($sDrive, 2 + $aDrive[0])
Return StringSplit($sResult, "")
EndFunc ;==>_GetEmptyDrives4
Func _GetEmptyDrives5()
Local $aDrive, $aEnum, $sResult, $iFlags
$aDrive = DriveGetDrive("All")
For $i = 1 To 26
$aEnum &= Chr(96 + $i)
Next
$aEnum = StringSplit($aEnum, "")
For $j = 1 To $aEnum[0]
$iFlags = 0
For $i = 1 To $aDrive[0]
If ($aEnum[$j] & ":" = $aDrive[$i]) Then
$iFlags = 1
ExitLoop
EndIf
Next
If $iFlags = 0 Then $sResult &= $aEnum[$j]
Next
Return StringSplit($sResult, "")
EndFunc ;==>_GetEmptyDrives5
Func _GetEmptyDrives6()
Local $sResult, $hFile
For $i = 1 To 26
$hFile = _WinAPI_CreateFile("\\." & Chr(96 + $i) & ":", 0, 0, 0, 0, 0)
If _WinAPI_GetLastError() = 2 Then $sResult &= Chr(96 + $i)
If ($hFile > 0) Then _WinAPI_CloseHandle($hFile)
Next
Return StringSplit($sResult, "")
EndFunc ;==>_GetEmptyDrives6
|