Looping a workflow for every file in folder

I want create a robot that starts a workflow when it finds a new txt file in a folder. My workflow looks like this Robot.xaml (13.6 KB) It worked without the For Each loop that i added but as soon as i add the loop i get following error message 19.7.0+Branch.master.Sha.8c253d13718eed5c7db27daef6facd1fe1b0d067

Source: Read Text File

Message: One or more errors occurred.

Exception Type: System.AggregateException

RemoteException wrapping System.AggregateException: One or more errors occurred. —> RemoteException wrapping System.IO.FileNotFoundException: Could not find file ‘C:\Users\Roman\Documents\UiPath\Test_Factoring\System.String’.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader…ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
at System.IO.File.ReadAllText(String path)
at UiPath.Core.Activities.ReadTextFile.<>c__DisplayClass13_0.b__0()
at UiPath.Core.Activities.Retry.Do[ResultType](Func`1 action, Int32 timeoutMS, Int32 retryCount)
— End of inner exception stack trace —

Server stack trace:
at UiPath.Core.Activities.Retry.Do[ResultType](Func`1 action, Int32 timeoutMS, Int32 retryCount)
at UiPath.Core.Activities.ReadTextFile.ExecuteAsync(String fileName, String encodingStr)
at UiPath.Core.Activities.ReadTextFile.<>c__DisplayClass12_0.b__0()
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object args, Object server, Object& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
at System.Func`1.EndInvoke(IAsyncResult result)
at UiPath.Core.Activities.ReadTextFile.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

any idea how to fix this?

Hi @re95

Easy way to do this is
1.Install UIpath.DirectorySearch.Activity package from manage packages.
2.In this you will find find Get Files activity in this In option search Directory give the path of Folder where you want to get Files.In option Filter you can give the extension of Files or you can use “.
3.store this in a List output variable in Output Option
4.use For each and read each single File.

Thanks & Regards,
A Manohar

@re95 As per your flow I I don’t see any trigger in your workflow, I mean for example it is a good option to check if a new file has arrived , as you have created a list of files , before you proceed to the for each to loop check if a new file has come or not by using a Counter or by using a Last Date approach once you have processed your current files you should move them to separate folder or delete it, so that the new files that come while your loop is being execute will only be processed next time.

Hi Greetings.!

Robot.xaml (14.9 KB) input_output files.zip (10.3 KB)

Modified your workflow. Running fine now. Attached Workflow, input and output docs.

Note:

  1. Please change file paths wherever required in xaml file
  2. Give Column name within quotes while using filter datatable activity. Please modify as i have changed.
  3. Dont create unnecessary variables.

Please let me know for any concerns.

Thanks!

1 Like

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