Get newest file in folder


I want that the BOT save the attachment from the Mail and start the process with this file.
This means that I can’t set a fixed path in e.g the Read Range activity, right? Because then it would work always with the same file…
The files always have the same name the only difference is the weeknumber at the end of the file (e.g Fcst cw27, Fcst cw28, …)


Hello Loons,
We talked something about this before (i will find the topic later).
So, when you download the attachment it has a fixed name (you can get this name).
After that, you can rename the file with something dynamic, something like current date + attachment name.
After that you can store that value in a variable and use Read Range activity or any other reading activity with that dynamic variable.

Hi @Loons
Yes so its better to get the last created file once after downloading the attachment and to get that
outfilepath = Directory.GetFiles(“yourFolderPath”,"*.yourfileextension”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0)

where outfilepath is a variable of type string

hope this would help you
Cheers @Loons


So, the path is this right?

But I get this error message…

1 Like

one second

we need to mention directory outfilepath as input to excel application scope
no other stuffs
only outfilepath
Cheers @Loons

It works :slight_smile:

Thank you very much

1 Like

Cheers @Loons

1 Like

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