I am trying to get latest excel files from a folder, and iterate those to write some text.
There are several files with the same modified date and time.
That is why I want to pull files as list type.
I use this Directory.GetFiles("Path")).Select(Function(f) New FileInfo(f)).OrderByDescending(Function(b) b.LastWriteTime).ToList(0).ToString
to get the latest files.
However when I assign a variable with above, I get an error:
How do I fix this?
@yesterday …tolist(0) will give you only one file output which is a string.
So if you want multiple files then just use .Tolist
Thank you for your reply.
That’s good to know.
I still get an error.
Do you know how to fix this?
@yesterday - please share the code which you are using and let us know your requirement clearly.
It should not end with .tostring
@yesterday - Correct Code should be like this…this will sort all the files in the folder based on last write time
str[] files = Directory.GetFiles("FolderPath").OrderByDescending(Function(f) New FileInfo(f).LastWriteTime).Toarray
If you want get the files with modified date today…
str[] files = Directory.GetFiles("FolderPath").where(function(x) new fileinfo(x).LastWriteTime.date = now.date).ToArray
If you want get the files with modified date today and orderbyDesending…
str[] files= Directory.GetFiles("FolderPath").where(function(x) new fileinfo(x).LastWriteTime.date = now.date).OrderBy(function(f) new fileinfo(f).LastWriteTime).ToArray
Hope this helps…
Thank you so much for your answer.
I will update this post when i get to work on the project. I havent started it yet.
Thank you,