Loop

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
boruciak
Posts: 18
Joined: 31 Aug 2018 09:06

Loop

Post by boruciak » 04 Mar 2019 11:11

Script (simplified entry):

OK="/STORAGE/OK";
P1="/STORAGE/AAA";
P2="/STORAGE/BBB";
P3="/STORAGE/CCC";
...
i=1;


How to save a loop for copying directories?

[Loop Start - Copy file]

Source: P{i} //I do not know how to make this record to have "/STORAGE/AAA"
Target: {OK}

[Script]
i=i+1

[goto loop start]

Tnx

User avatar
Desmanto
Posts: 1757
Joined: 21 Jul 2017 17:50

Re: Loop

Post by Desmanto » 04 Mar 2019 19:00

You can create dynamic variable using eval(). If you loop against i, and the variable name are in the loop, you can use something like

Code: Select all

aaa = eval("P{i}"); // eval("P1") >> then "/STORAGE/AAA"
But for your case, this is not the optimized method. You should use list instead, it is much easier to iterate over each element.

Code: Select all

files = newList(
"/STORAGE/OK",
"/STORAGE/AAA",
"/STORAGE/BBB",
"/STORAGE/CCC" );
files now contains 4 elements, which you can loop later. If you need the loop only inside a script, example to change STORAGE become EXTERNAL, this is the loop script. (just example)

Code: Select all

for(i in [0 to length(files)-1])
  files[i] = replace(files[i], "STORAGE", "EXTERNAL");
If you want to "loop copy", there is no need to do so. You can simply use action Copy Files (with s), and use the files directly in listformat comma delimited. At the source, put
Source : {files,listformat,comma}
Target : /Targetpath/folder
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190512, Pie 9.0, Rooted.

boruciak
Posts: 18
Joined: 31 Aug 2018 09:06

Re: Loop

Post by boruciak » 04 Mar 2019 21:44

Thanks a lot Desmanto!

Post Reply