General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
Posts: 20
Joined: 31 Aug 2018 09:06


Post by boruciak » 04 Mar 2019 11:11

Script (simplified entry):


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}


[goto loop start]


User avatar
Posts: 2599
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(
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), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Posts: 20
Joined: 31 Aug 2018 09:06

Re: Loop

Post by boruciak » 04 Mar 2019 21:44

Thanks a lot Desmanto!

Post Reply