Need to open the last file in my Folder

@prasath17
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

image

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

1 Like

@prasath17
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

@prasath17

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

@prasath17
image

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
image

Show us the error and your assign statement??

1 Like


image

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

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

2 Likes

Hi @Soudios,

I would advice you do either draw a simple folder structure schematic

OR even better

Make a zip of your folder structure (without your required file name and type)

This way @prasath17 can guide you easily.

A side note :
@prasath17 i wonder how many Regex expressions are hidden in that RegexPractice folder of yours! :wink:

3 Likes

@prasath17
it works thank you ! :slight_smile:

@jeevith … Ha ha… :wink:… It is actually here…

image

2 Likes

You are a regex master @prasath17 :blush::blush::blush:

2 Likes

@NIVED_NAMBIAR - Not yet…Still learning everyday and honing my skills

2 Likes

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