How to iterate multiple arrays (list) with nested loop

I am having an issue when iterating two arrays.

What I am trying to do is copy (move) two excel files (Source files) to a specified folder (destination folder), and set the copied file’s attribute as read-only.
image

It is a simple process but I have two files to do the same steps, so I want to iterate their paths.

The excel files are updated and overwritten when copied.

Those files in the destination folder are set to read-only. In order to overwrite the files, it needs to remove read-only attributes, and after copying (Overwriting)the files, it adds read-only attribute again.

What I am stuck is to iterate file paths.
Below image is the process I created so far, but this is wrong.

It should iterate file1 (Array1) in the parent For Each, and file1 (Array2) in the first iteration, and the second iteration, file2 (Array1) in the parent For Each, and file2 (Array2) in the second ForEach. but in my case, it iterates file1 (Array1) in the parent Foreach, and file1 and file2 (Array2) in the nested ForEach.

How do I iterate these arrays??

Hi @yesterday,

Although there will be a way to iterate the two arrays simultaneously and do the actions (move and read only),I suggest you to rethink the approach.

Since you already know the file paths in array1 you could first move/copy the files.

For file in array1 (use Index Property and store it as variable)
Action: Copy file with NewRequiredName

Where NewRequiredName = Array2(Index).ToString

For filepath in Array2
Covert to read only

This way you don’t have to use nested loops instead use two different for loops to perform your automation.

Another thing I liked in your question is that you drew the approach, I can guarantee you that your future solutions will benefit from the work you put into such drawings. It will help you a lot to think clearly and you can get feedback from your colleagues when you get stuck if you have good mental models.

Thank you so much for your answer. I tried separating the processes, but I ended up using While loop by counting the array and iterating the number of the count.

Thank you so much for your kind words. That motivates me to improve my knowledge. I always try to write my questions that can be understand at once for everyone so that I can get the answer faster.
I will continue learning!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.