Jump to content

Change The To Value In A For Loop, Inside The Loop?


Recommended Posts

I have a For loop with an undetermined To value...

$ArraySize = (UBound($SystemDrives)-1)
For $i = 1 to $ArraySize
    If DriveGetFileSystem($SystemDrives[$i]&"\") = "NTFS" Then
        _ArrayDelete($SystemDrives, $i)
        $SystemDrives[0] = $SystemDrives[0] - 1
        $ArraySize = $ArraySize - 1
    EndIf
Next

However, it seems to just take the initial value of the $ArraySize and that is that. How can I make this loop go through the array until its end, if the size of the array is changing as the loop is running? I keep overstepping the arrays bounds.

Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Jeez... Why didnt I think of that?? I'm going to say because its late :think:.

This works a treat:

For $ArraySize = UBound($SystemDrives) to 1 Step -1
    If DriveGetFileSystem($SystemDrives[$ArraySize - 1]&"\") = "NTFS" Then
        _ArrayDelete($SystemDrives, ($ArraySize - 1))
        $SystemDrives[0] = $SystemDrives[0] - 1
    EndIf
Next

Thanks greenmachine.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Jeez... Why didnt I think of that?? I'm going to say because its late :think: .

This works a treat:

For $ArraySize = UBound($SystemDrives) to 1 Step -1
    If DriveGetFileSystem($SystemDrives[$ArraySize - 1]&"\") = "NTFS" Then
        _ArrayDelete($SystemDrives, ($ArraySize - 1))
        $SystemDrives[0] = $SystemDrives[0] - 1
    EndIf
Next

Thanks greenmachine.

It took me a while to figure it out too. I was trying to store it in different variables, or storing the ones to delete in another array and then deleting them afterward (way too complicated, and is more or less the same as you had it), and then I realized ("D'OH") - just do it like I do folds in Scite. If you do it in reverse, the ones you delete only affect the ones you've already passed over. And there you have it, a revelation.

Oh, and you're welcome.

Edited by greenmachine
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...