Jump to content

How to loop multiple variables within an array?


Recommended Posts

Hi everybody.
Trying to learn some Autoit and move form an old batch file that did back ups, and had served me well.
I'm trying to use 'SQlite' to do some file maintenance on files in back up location (then back them up). 'Vacuum' , 'reindex' and 'analyze', are the three things I'm trying to 'run' on each of the SQlite files the script finds. I have the script written, and it works great. Except I cannot figure out how to loop it? I'm not even sure that is the right word to use.

I'm stuck and would appreciate any help or ideas to get past this hurdle.

Thanks for looking and offering any input.

#include <File.au3>
#include <Array.au3>

$FileList = _FileListToArray(@AppDataDir & "\Moonchild Productions\Pale Moon\Profiles\od3oy6iu.default", "*.sqlite")
If @error = 1 Then
    MsgBox(0, "", "0 Files found.")
    Exit
EndIf
if isarray($FileList) then ConsoleWrite('Number of files returned = ' & $FileList[0] & @LF)
; ConsoleWrite($FileList & @LF)
_ArrayDisplay($FileList, "$FileList") ; Debug

$a1 = "vacum"
$a2 = "reindex"
$a3 = "analyze"



For $i = 1 To $FileList[0]




Local $param01 = "D:\[[Command]\sqlite3.exe"
Local $param05 = "  "
Local $param10 =  $FileList[$i]
Local $param15 = "  "
Local $param19 = $a1



; Run SQLite
Local $sRun = $param01&$param05&$param10&$param15&$param19
ConsoleWrite(' $sRun >'&$sRun&'<'&@CRLF) ; ..this way you can see what is gonna execute
; RunWait($sRun, "", @SW_MAXIMIZE)


Next
Number of files returned = 7
 $sRun >D:\[[Command]\sqlite3.exe  content-prefs.sqlite  vacum<
 $sRun >D:\[[Command]\sqlite3.exe  cookies.sqlite  vacum<
 $sRun >D:\[[Command]\sqlite3.exe  formhistory.sqlite  vacum<
 $sRun >D:\[[Command]\sqlite3.exe  permissions.sqlite  vacum<
 $sRun >D:\[[Command]\sqlite3.exe  places.sqlite  vacum<
 $sRun >D:\[[Command]\sqlite3.exe  storage.sqlite  vacum<
 $sRun >D:\[[Command]\sqlite3.exe  webappsstore.sqlite  vacum<

 

Link to comment
Share on other sites

Can you say if you want to do exact same code 2 time ? or the same code with some changes ? 

 

If yes. Whitch will be the changes ? 

 

If you want to Start again from Zero. Take a look at RestartUDF.au3 

If you want to while more time the same script you can just While (1) everything. 

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

4 hours ago, caramen said:

Can you say if you want to do exact same code 2 time ? or the same code with some changes ? 

I would like to do the exact same code - except changing the line 'Local $param19 = $a1' to 'Local $param19 = $a2, for the 2nd run, and for the 3rd run to 'Local $param19 = $a3'.

I'm getting stumped on how to use the changing variables. 

$a1 = "vacum"
$a2 = "reindex"
$a3 = "analyze"

Local $param19 = $a1 ; 1st run
loop
Local $param19 = $a2 , 2nd run
loop
Local $param19 = $a3 , 3rd run
exit loop

 

Link to comment
Share on other sites

Just loop within the loop, for example:

Local $aMaintenance[4] = [3, "vacum", "reindex", "analyze"]
Local $sCommand
For $i = 1 To $aMaintenance[0]
    For $j = 1 To $FileList[0]
        $sCommand = "D:\[[Command]\sqlite3.exe " & $FileList[$j] & " " & $aMaintenance[$i]
        ConsoleWrite(" $sCommand : " & $sCommand & @CRLF)
;~      Ctrl + Q to uncomment line below
;~      RunWait($sCommand, "", @SW_MAXIMIZE)
    Next
Next

 

Edited by Subz
Added scope
Link to comment
Share on other sites

@subz. Thanks a lot , with a few tweaks it works perfectly. Also I should be able to use this elsewhere, so many doors have opened.
Though, strangely, I was getting error message on the line '$aMaintenance[4] = [3, "vacum", "reindex", "analyze"]'. 

Now I can move on in my script, thanks again :)

$aMaintenance[4] = [3, "vacum", "reindex", "analyze"]  <-- Error 'possibly used before declaration.'
Local $aMaintenance[4] = [3, "vacum", "reindex", "analyze"]  <-- works, I have no idea why.

 

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...