Page 1 of 1

Loop

Posted: 04 Mar 2019 11:11
by boruciak
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

Re: Loop

Posted: 04 Mar 2019 19:00
by Desmanto
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

Re: Loop

Posted: 04 Mar 2019 21:44
by boruciak
Thanks a lot Desmanto!