Hi all, in my case, I have a folder that contains 12 folders (which one represents one company).
In those 12 folders, I have several excel file downloaded from the website.
My task is to open the most recent excel file for each of the folder.
I use ‘for each folder in folder’ activity at the beginning, but I’m lost and don’t know how should I do to get the file in each folder when the folder is in another folder.
Use a for loop to loop through the folders by giving the main folder as Input.
Inside the for loop use the following expresssion Directory.GetFiles().OrderByDescending(function(s) System.IO.file.GetCreationTime(s)).First() to get the latest file. Path will be the for loop item (which is the folder path of each of 12 folders inside main folder)
Directory.GetDirectories() will give you all folders as array
Then loop through array using for loop
In the for loop add assign and use Directory.GetFiles().OrderByDescending(function(s) System.IO.file.GetCreationTime(s)).First() this to get the latest file path.
Instead of 1 and 2 you can use for each folder in folder as well
So you need to use only one for loop for the directories
Please check the following videos about getting the newest file from a directory in different methods or also how to loop files in different folders and subfolders:
and also, this is the error detail: [compare.xaml: Compiler error(s) encountered processing expression “CurrentFolder.GetFiles(Str_directoryPath,”*.xlsx").OrderByDescending(Function (p) p.LastWriteTime)(0).FullName".(2) : error BC30518: Overload resolution failed because no accessible ‘GetFiles’ can be called with these arguments:
‘Public Overloads Function GetFiles(searchPattern As String, searchOption As SearchOption) As FileInfo()’: Option Strict On disallows implicit conversions from ‘String’ to ‘SearchOption’.
‘Public Overloads Function GetFiles(searchPattern As String, enumerationOptions As EnumerationOptions) As FileInfo()’: Value of type ‘String’ cannot be converted to ‘EnumerationOptions’.]