Im trying to create some code in Access which will loop through a folder i.e. C:\Users\ANON\LotsofSubFolders and find the most recent file in all of the subfolders that matches a specific name.
For Example, in C:\Users\ANON\Data there is a folder for this 2018, 2019... and inside each 2018 and 2019 there is another folder i.e. Jan, Feb, etc. I want to be able to find the most recent file named "FindFile_1.xlsx".
Example File Paths: C:\Users\ANON\Data\2019\Jan\FindFile_1.xlsx C:\Users\ANON\Data\2019\Feb\FindFile_1.xlsx C:\Users\ANON\Data\2018\Dec\FindFile_1.xlsx
I have been able to use the following script to find the first subfolder i.e. 2018 or 2019, however it does not go down the next level and so on.
Sub GetSubFolderNames()
Dim MyFSO As FileSystemObject
Dim MyFile As File
Dim MyFolder As Folder
Dim MySubFolder As Folder
Set MyFSO = New Scripting.FileSystemObject
Set MyFolder = MyFSO.GetFolder("C:\Users\sumit\Desktop\Test")
For Each MySubFolder In MyFolder.SubFolders
Debug.Print MySubFolder.Name
Next MySubFolder
End Sub
Im then faced with the challenge of trying to the find the most recent file named xxxx once i have all of the subfolders.