Jump to content

fetch DriveGetDrive to array


Recommended Posts

       Global $RemDL
       Global $dt[0]

    $RemDL = DriveGetDrive($DT_FIXED)
    If  NOT @error Then 
    For $i = 0 To UBound($RemDL) - 1
        ReDim $dt[$i + 1]
        $dt[$i] = StringReplace(StringReplace(StringUpper($RemDL[$i]), "C:", ""), "F:", "")
        If $dt[$i] = "" Then ReDim $dt[$i - 1]
   Next

    _ArrayDisplay($dt)

endif

Trying to get fix drives as array in proper manner got 4 drives (c: d: e: f:) but getting  5 rows as array which i want to display as 2 drives (2 rows) only d: and e:
 

Edited by autoitxp
Link to comment
Share on other sites

Thanks ! 

 
#include <Array.au3>

Global $RemDL
Global $dt[0]

Func _DriveR()
    $RemDL = DriveGetDrive($DT_ALL)
    If @error Then Return SetError(-1)
    For $i = 1 To UBound($RemDL) - 1
        If $RemDL[$i] = "A:" Or $RemDL[$i] = "B:" Then ContinueLoop
        _ArrayAdd($dt, $RemDL[$i])
        If @error Then Return SetError(-1)
    Next
    If UBound($dt) = 0 Then Return SetError(-1)
    Return $dt
EndFunc   ;==>_DriveR

 

Edited by autoitxp
Link to comment
Share on other sites

Number of ways, _ArrayDelete and ReDim

#include <Array.au3>

Global $aAllDrives = _Example1()
_ArrayDisplay($aAllDrives)

Func _Example1()
    Local $aAllDrives = DriveGetDrive($DT_ALL)
        If @error Then Return SetError(-1)
    _ArrayDelete($aAllDrives, 0) ;~ Remove the first row
    For $i = UBound($aAllDrives) - 1 To 0 Step - 1
        If $aAllDrives[$i] = "A:" Or $aAllDrives[$i] = "B:" Then _ArrayDelete($aAllDrives, $i)
    Next
    Return $aAllDrives
EndFunc

#include <Array.au3>

Global $dt = _Example2()
_ArrayDisplay($dt)

Func _Example2()
    Local $RemDL = DriveGetDrive($DT_ALL)
    Local $aDT[0]
        If @error Then Return SetError(-1)
    For $i = 1 To UBound($RemDL) - 1
        If $RemDL[$i] = "A:" Or $RemDL[$i] = "B:" Then ContinueLoop
        ReDim $aDT[UBound($aDT) + 1]
        $aDT[UBound($aDT) - 1] = $RemDL[$i]
    Next
    If UBound($aDT) = 0 Then Return SetError(-1)
    Return $aDT
EndFunc   ;==>_Example2

 

Link to comment
Share on other sites

_arraydelete uses ReDim internally. Almost any array UDF that resizes an array, by adding or deleting some row/column will use it.

There are better ways to do it, namely by copying the array to another array, and not copying the parts you don't want. Then return the copied array.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

1 hour ago, BrewManNH said:

_arraydelete uses ReDim internally. Almost any array UDF that resizes an array, by adding or deleting some row/column will use it.

There are better ways to do it, namely by copying the array to another array, and not copying the parts you don't want. Then return the copied array.

if you can put  code here by using @Subz _example1(). 

Link to comment
Share on other sites

Why? How many drives do you have that would affect the speed of your code that much such  that any reduction in speed by using ReDim would shave off nanoseconds?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

its loop to check fixed drives and fixed labels  almost 500.  drives keep coming online and going my I am trying to get array of drives at gr8 speed as possible some of drives also need to block from displaying as above example A: AND B: 
 

 

Edited by autoitxp
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...