If I insert new files into a folder that’s undergoing a for each file in folder loop, do the new files get used?

I am running an automation that uses for each file in folder. The folder in question is a shared one, would new files added to it while the automation is running be used for the automation?

Directory.GetFiles(Path) will only give you list of files available in the folder at that point of time and for each loop will be looping through those files.

If you want to process dynamically added files, you can add a wait when count= 0 and then retry for as many times as you need. And can also configure the wait time as per your requirement.

HI,

Unfortunately, No. If it’s necessary to process a file after starting ForEachFileInFolder, check if there is unprocessed file after loop then do it again. For example, as the following.( This sample moves processed files then check number of files in the folder at the end.)

Or FileChangeTrigger may also help you.

Regards,

Yes, in most cases the automation will use new files added to the folder while it is running. This depends on what folder monitoring mechanism you use in your automation. For example, if you use a loop to process files in a folder, then new files added to the folder while the automation is running will also be processed. However, if your automation does not monitor changes in real time, then new files may be missed.