i am supposed to iterate through my folder and add the file names in my file into a dictionary , then use the existing dictionary (e.g 60 files) as a reference for the next marco run, on the next marco run, if my folder doesn't have any changes and the 60 file names matches the dictionary exactly the same, then do nothing. However if there are changes to the folder, e.g 3 new files are added into the folder, then once again it checks whether it matches the dictionary containing the 60 files if it doesn't, update the dictionary will the new file names then, i will have to "do something" but only to the 3 new files not the 60 existing files unless any of the 60 existing files got deleted.
I believe the code does what i want but something is missing, despite adding files into the folder, it does not update the dictionary, and despite it being the same amount of files, it still "do something".
Is it because i have not yet created a dictionary to add my filenames into? or what might be the reason?
I have never used dictionary before in any platform and have no knowledge about it, please pardon my novice questions.
Please advice me on it any help will be deeply appreciated.
Code provided by JvdV Excel Vba avoid repeated extraction of data
Public Dict As Object
Sub Test()
Dim oFSO As Object, oFolder As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Users\Desktop\asi")
If Dict Is Nothing Then
Set Dict = CreateObject("Scripting.Dictionary")
End If
For Each oFile In oFolder.Files
If Dict.Exists(oFSO.GetBaseName(oFile)) Then
'Skip file
Else
'Don't skip file and do something....
'Add to dictionary for next iteration
Dict.Add oFSO.GetBaseName(oFile), 1
End If
Next oFile
Range("A1").Resize(UBound(Dict.Keys)).Value = Application.Transpose(Dict.Keys)
End Sub