patrickb

drivergetdrive drivegettype combined

6 posts in this topic

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

 

 

Share this post


Link to post
Share on other sites



What have you tried so far?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

 

 

 

 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Water,

wow and thanx. Something to study this weekend :)

Just tried it and returns everything but not my usb flashdrive. Any idea why ?

 

Share this post


Link to post
Share on other sites

oops already figured it out. Again thanx

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now