patrickb Posted January 22, 2016 Share Posted January 22, 2016 Hi there, i'm having some difficulty getting the following to work. I have two functions (found it somewhere on this forum, so it is NOT my code) that i would like to combine into one function. My goal is to query drives and drivebustype into one function in one go. Examples query for fixed and removable drives with a usb bustype script.exe "fixed|removable" "usb" query for fixed and removable drives with a usb or scsi bustype script.exe "fixed|removable" "usb|scsi" query for all drives script.exe "all" "all" Really hope anyone can help me, cause i'm not seeing the light at the end of the tunnel. here are the functions, they work fine as seperate functions Func _GetDriveByBusType($drives = 'ALL', $types = 'ALL', $delimiter = '|') Local $1, $string If StringRegExp($delimiter, '[a-zA-Z:]') Then Return SetError(1, 0, 0) $types = $delimiter & $types & $delimiter $drives = DriveGetDrive($drives) For $1 = 1 To UBound($drives) -1 If StringInStr($types, $delimiter & DriveGetType($drives[$1],$DT_BUSTYPE) & $delimiter) Then $string &= $drives[$1] & $delimiter Next $string = StringTrimRight($string, StringLen($delimiter)) Return StringSplit($string, $delimiter, 3) EndFunc Func _DriveGetDriveByType($types = 'ALL', $delimiter = '|') Local $1, $drives, $string If StringRegExp($delimiter, '[a-zA-Z:]') Then Return SetError(1, 0, 0) $types = $delimiter & $types & $delimiter $drives = DriveGetDrive('ALL') For $1 = 1 To UBound($drives) -1 if DriveStatus($drives[$1] & '\') = 'READY' Then If StringInStr($types, $delimiter & DriveGetType($drives[$1]) & $delimiter) Then $string &= $drives[$1] & $delimiter EndIf Next ConsoleWrite(@CRLF & $string & @CRLF) $string = StringTrimRight($string, StringLen($delimiter)) if not $string = '' Then Return StringSplit($string, $delimiter, 3) Else ConsoleWrite(@CRLF & "COMPUTER SAYS : nothing to do" & @CRLF) Exit EndIf EndFunc ;==>_DriveGetDriveByType Link to comment Share on other sites More sharing options...
water Posted January 22, 2016 Share Posted January 22, 2016 What have you tried so far? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
patrickb Posted January 22, 2016 Author Share Posted January 22, 2016 Hi Water, thanx for your reply and i get your point. There's no free lunch So far i have the following working. Been fiddling alot script.exe "fixed" "usb" returns my external real hd usb drive letters. script.exe "removable" "usb" returns my external flashdrive everything else fails. $drive1 = _GetDriveByBusType($cmdLine[1], $cmdLine[2]) If IsArray($drive1) Then ConsoleWrite(@CRLF & _ArrayToString($drive1, ";") & @CRLF) EndIf Func _GetDriveByBusType($drives = 'ALL', $types = 'ALL', $delimiter = '|') Local $1, $string If StringRegExp($delimiter, '[a-zA-Z:]') Then Return SetError(1, 0, 0) $types = $delimiter & $types & $delimiter $drives = DriveGetDrive($drives) For $1 = 1 To UBound($drives) -1 If StringInStr($types, $delimiter & DriveGetType($drives[$1],$DT_BUSTYPE) & $delimiter) Then $string &= $drives[$1] & $delimiter Next $string = StringTrimRight($string, StringLen($delimiter)) Return StringSplit($string, $delimiter, 3) EndFunc Link to comment Share on other sites More sharing options...
water Posted January 22, 2016 Share Posted January 22, 2016 (edited) How about this? Returns an array with the drive letter, drivetype and bustype for each found drive: #include <Array.au3> #include <AutoItConstants.au3> Global $aDrives[0] $aDrives = _DriveGetDriveByTypes("fixed|cdrom", "all") _ArrayDisplay($aDrives) Exit Func _DriveGetDriveByTypes($sDriveTypesParam = "ALL", $sBusTypesParam = "ALL") Local $i, $aDrives, $sDriveTypes, $sBusTypes, $aResult[0][3], $iRecord = 0, $iPos $sDriveTypes = "|" & $sDriveTypesParam & "|" $sBusTypes = "|" & $sBusTypesParam & "|" $aDrives = DriveGetDrive('ALL') For $i = 1 To UBound($aDrives) - 1 If DriveStatus($aDrives[$i] & '\') = 'READY' Then $iPos = StringInStr($sDriveTypes, "|" & DriveGetType($aDrives[$i], $DT_DRIVETYPE) & "|") If $iPos > 0 Or $sDriveTypesParam = "ALL" Then $iPos = StringInStr($sBusTypes, "|" & DriveGetType($aDrives[$i], $DT_BUSTYPE) & "|") If $iPos > 0 Or $sBusTypesParam = "ALL" Then ReDim $aResult[UBound($aResult, 1) + 1][3] $aResult[$iRecord][0] = $aDrives[$i] $aResult[$iRecord][1] = DriveGetType($aDrives[$i], $DT_DRIVETYPE) $aResult[$iRecord][2] = DriveGetType($aDrives[$i], $DT_BUSTYPE) $iRecord = $iRecord + 1 EndIf EndIf EndIf Next Return $aResult EndFunc ;==>_DriveGetDriveByTypes Edited January 22, 2016 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
patrickb Posted January 22, 2016 Author Share Posted January 22, 2016 Hi Water, wow and thanx. Something to study this weekend Just tried it and returns everything but not my usb flashdrive. Any idea why ? Link to comment Share on other sites More sharing options...
patrickb Posted January 22, 2016 Author Share Posted January 22, 2016 oops already figured it out. Again thanx Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now