How to get filename of latest downloaded file


I had been browsing the forum and haven’t met any suitable answer

So basically I need to download a file (the name will be generated randomly by system).
I need to do several activities after the download finished so I use file change trigger inside monitor events to let the robot know that a file has been created. But I am confused about what to pass as the filename to trigger the event because it will be generated randomly.

My questions are:

  1. does my process considered as a good method or are there other simpler methods?
  2. how to get the file name after it finished downloaded and passed it to the FileName.


Thank you in advance


This query will get you latest updated file from a directory,

Directory.GetFiles(path).[Select](Function(x) New FileInfo(x)).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()

thank you for the reply.

I got error when passing that as a filename

did i do it correctly or not?

i also have tried to assign it in a variable and get the same error

@rookies - you will get a array variable (having list of filenames), so you need to take array index of your filename to get the value.

May i know how many files and from the file is downloaded, will you be giving a name for it or will be downloaded as it is with its own name
Cheers @rookies





i have assign it to string array variable and it still turn error.

but how to make the get array list activity starts after the file finished downloading?

thanks for the reply. only 1 files will be downloaded and it will be downloaded as its own name. please help

Replace .Take(1).ToArray() with .first()

@paul.placintar I did that and it return this error

Since my downloaded files will be the extension of xlsx, i try to pass “*.xlsx” as filename but it didnt trigger the next process.

is there any way to pass excel file extension only as filename?

reference is from this


The below line give me the latest .xlsx file from a folder,

Directory.GetFiles(path).[Select](Function(x) New FileInfo(x)).Where(Function(f) f.Extension.Equals(".xlsx")).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()(0).ToString()

Here path is my string variable to hold the directory path value


Thank you. It works. But I couldn’t use this on file change trigger because the process executed right away after i click download button. so it would not get the latest downloaded file as it is still on progress of downloading (it would get the other excel file on that folder instead)

What is the best way to make sure that this activity starts after the download finished?


From where you downloading the file, I think you can use this snippet to download file from Internet Explorer.

Else, use Path exist activity to ensure the download completed.

After further tinkering. I finally be able to get what i want by passing this as the criteria in the filename

however your solution helped me to determine the latest excel file name in the folder and I am able to continue the process with that file

Thank you


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