How to open the first file that contains a certain file prefix

I’m trying to open a PDF file inside a certain directory.
Right now, I’m experimenting with the “For each” activity via
Foreach [file] in [Directory.GetFiles(filePath, “new_*.pdf”)]

As you can see, I’m trying to get all the files that has the “new” word at the beginning of the file name. At the body, I put a Start Process activity and would like to open the “file” first iteration. I tried “file.First” but it’s returning an error:

> Main has thrown an exception
**> **
> Source: Start process
**> **
> Message: The system cannot find the file specified
**> **
> Exception Type: Win32Exception
**> **
> System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
> at UiPath.Core.Activities.TaskAsyncCodeActivity`1.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)

I also tried just putting simply “file” in the FileName field of the “Start Process” activity - it does open the files, but it opens all of the ones with “new” in their file names.


I’m seeking to know how I can open the first file > scrape/gather data > close file > open next file > and so on. Sorta kinda loop way of doing things.

Please do correct me if I asked in a wrong manner. I am somewhat new to the community. Thanks in advance!

Hi @Jep_De_Guzman

In first row you have to give the application exe and then next you have to give the file path as a argument.
Hope this will helpful to you

JothyPrasanth M

First try to do write line activity to see file is getting expected value