Need to open the last file in my Folder

i used this : String.Join(“”, Directory.GetFiles(ExcelFile1,”*”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).LastWriteTime).Take(1))

But i have an oder folder inside the first one and i have new files into it. The bot doesnt stop to the first folder it takes the last file into the second folder, is it normal with this sentence ?

i want that the bot takes the last file in the first folder

Use array
Listofarr-Get all files from folder

You can choose the last one

Check and let me know whether it’s working or not

1 Like

The last one of the first folder ?
Where i need to add you sentence ?

why you are looking only in the first subfolder??? what is the condition for that??

So you

Parent Holder A
Subfolder Structure
B ==> Pick the last file from this folder??

1 Like

Because after traitment a new file is created in the second folder.

Folder 1 / Folder 1.1

I want the last file in the folder 1 not 1.1

My question is how to pick the Folder 1? what is the criteria for that??

1 Like

Don’t really undersand your question.

Example : C\user\Folder1\Folder2

I need : C\user\Folder1\lastfile.xlsx

In the below screenshot , I have lot of folders inside the folder “Studio” if i want to pick the “Misc xaml” folder then I have to go with LastWritetime…And then read the “Misc Xaml” folder to check last file


Like this…what is the first condition to choose from the list of folders??

1 Like

There is only one folder and in this folder there is an oder folder.

But if you need a condition it’s to open the folder named : EXCEL FOLDER

Still I do not understand. But just remove this option and try. Above option will search for all the subfolders so if you do not want that, just remove and give it a try.

1 Like


Ok just to be clear, if i take your screen you have the folder Studio its the equal of my folder 1 and you have the folder Misc xaml its the equal of my folder 2.

So i have files in Studio folder and files in Misc folder, with my sentence the bot takes the last file in Misc Folder not in Studio Folder. What i need is it takes the last file in Studio Folder

@Soudios - Got it…

 Directory.GetFiles(ExcelFile1).OrderByDescending(Function(d) New FileInfo(d).LastWriteTime)

Above code will give the recent file from the folder…if you want the older file then please try the below code…

Directory.GetFiles(ExcelFile1).OrderBy(Function(d) New FileInfo(d).LastWriteTime)
1 Like


In (Excelfile1) i put the link of the folder

@Soudios … StrRecentFile and StrOlderFile is String Variables…

StrRecentFile=Directory.GetFiles(ExcelFile1).OrderBydescending(Function(d) New FileInfo(d).LastWriteTime).First

StrOlderFile=Directory.GetFiles(ExcelFile1).OrderBy(Function(d) New FileInfo(d).LastWriteTime).First

In my sentence i put the link here :
String.Join(“”, Directory.GetFiles(LINK,”*”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).LastWriteTime).Take(1))

How can i do the same with your sentence ?

I gave the perfectly working code…I am not sure why are going back with your old code which is having “SearchOption.AllDirectories”…I already told that, if you add this code, bot will look for all the subfolders…that’s why in my code I have removed it…

I am not sure, what exactly you are trying to acheive with String.join. String.Join will help if you have to multiple strings. In your code, since you gave take(1), there will be only one string output.

please refer below…

1 Like

ok but i have still this error

Show us the error and your assign statement??

1 Like


@Soudios - Below will a array…and your assign statement is string…

please read the below again and add .first at the end…