in reply to Array not accessible in foreach loop

Are you certain that @branchesSelected is being populated with anything?

What I'm getting at is: are you sure that the foreach loop in question is even being run? If there are no values in @branchesSelected, then that loop would in effect never be processed.

You only displayed log entries that have to do with the first loop where @selectedFiles gets populated. So I don't know if this is because no other logging occurred after that?, or if you simply did not include those entries.