How to make For each start with a specific item and run the whole list too?

Basically i am looping through a Folder using the Directory.GetFiles and For each . My Requirement is to Loop a specific file name first no matter how many files are in the folder, name of the file is almost static so we can target that if needed.

Scenario 1

  • Folder have files A,B,myfile,D

  • Loop order = myfile,A,B,D

Scenario 2

  • Folder have files A,B,G,I,L,myfile,K

  • Loop order = myfile,A,B,G,I,L,k

order of other files don’t matter, have to have ‘myfile’ loop first, How can i do this ? Thanks in advance

Attaching Workflow
test.xaml (8.2 KB)

you can use this pattern to search files in directory. It will first pick your file.Directory.GetFiles(attachFolderLocation,“myfile”)

but this would only pick the file “myfile”, and wont pick the A,B,C etc files. Requirement is to loop all files but loop the “myfile” first (in the same loop)

Check this:

Upload.xaml (9.6 KB) !


Just use the file you want first, before getting the files, inside your for each, put an if condition to avoid processing that file again…

its weird situation, we have to have this all in the same loop due to a big portion of the existing code.

put the code in a separate wf file…

Great this works like a charm

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