Paralell For Each Item in Directory

Hi!

I have a working automation that;

  1. Loops through .csv files in Folder1 … For Each “item” in “Directory.GetFiles([Folder1])”
  2. Copy File from a “[Source .xslx file]” which is saved in Folder2, makes the copies to “[Folder3]”
  3. Read CSV [item.tostring] output [DataRange]
  4. Excel Application Scope “[the newly created .xlsx file which lives in in Folder3]”
  5. Write Range [DataRange] into “[the newly created .xlsx file which lives in in Folder3]”

The process will therefore take the template file in Folder2, and ForEach file in Folder1, create a copy of the Template in Fodler3 and dump the Folder1 data into it.

Now… As this automation need to executed roughly 300 files each time it is run, I have looked at speeding this process up with a parallel, however I get this error;

ERROR Validation Error Compiler error(s) encountered processing expression “Directory.GetFiles([Folder1])”
Option Strict On disallows implicit conversions from ‘1-dimensional array of String’ to ‘System.Collections.Generic.IEnumerable(Of Integer)’.

Could somebody please advise what argument is needed to enable a parallel run on directory files? As far as I can see, there should be no parallel execution issues as no file is open/needed by the same process, however the variable names used during the loop with be similar.

I have never used a parallel before so appreciate any guidance!

Thank you

Hi,

Can you try to set String at TypeArgument property of Parallel For Each activity?

Regards,

Thanks, that made the loop work! :slight_smile:

I now have a different error on the “Write Range” activity, it successfully writes data to the first excel file but cannot write to any subsequent files… when the automation in studio hits a paused state on error, I try to open the second and third etc. files, but it says “locked for editing”, I assume this is the reason for the Write Range activity failing?

I tried to run a kill-process on all Excel prior to running the script but it dosn’t seem to work.

P.S. - This doesn’t happen when “Visible” is ticked for the excel scope, however with visible ticked it opens all the files and then closes them all, and they are 4mb files so it is a very slow process (almost faster to run as a sequently loop not parallel loop because then there is no resource strain from multipole files open and they seem to open/close faster.

Has anyone come across this whilst trying to parallel process excel files?