autoitxp Posted October 3, 2018 Share Posted October 3, 2018 (edited) 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 October 3, 2018 by autoitxp Link to comment Share on other sites More sharing options...
Subz Posted October 4, 2018 Share Posted October 4, 2018 Not really sure what you're trying to achieve, but maybe something like: #include <Array.au3> Global $RemDL Global $dt[0] $RemDL = DriveGetDrive($DT_FIXED) If @error Then Exit For $i = 0 To UBound($RemDL) - 1 If $RemDL[$i] = "C:" Or $RemDL[$i] = "F:" Then ContinueLoop _ArrayAdd($dt, $RemDL[$i]) Next _ArrayDisplay($dt) Link to comment Share on other sites More sharing options...
autoitxp Posted October 4, 2018 Author Share Posted October 4, 2018 (edited) 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 October 4, 2018 by autoitxp Link to comment Share on other sites More sharing options...
autoitxp Posted October 5, 2018 Author Share Posted October 5, 2018 Subz what if i don't need to use _arrayadd as _arrayadd use redim in loop any other way to delete array and fetch correct array on call Link to comment Share on other sites More sharing options...
Subz Posted October 5, 2018 Share Posted October 5, 2018 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 More sharing options...
autoitxp Posted October 5, 2018 Author Share Posted October 5, 2018 @Subz First example is good as not using redim in loop thanks Link to comment Share on other sites More sharing options...
BrewManNH Posted October 5, 2018 Share Posted October 5, 2018 _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 GudeHow 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 More sharing options...
autoitxp Posted October 5, 2018 Author Share Posted October 5, 2018 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 More sharing options...
BrewManNH Posted October 5, 2018 Share Posted October 5, 2018 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 GudeHow 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 More sharing options...
autoitxp Posted October 5, 2018 Author Share Posted October 5, 2018 (edited) 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 October 5, 2018 by autoitxp 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