Hello,
I have two folders that contain a number of .xlsx files. Some of the files in Folder1 are also found in Folder2. I want to keep the files that are common in both folders, and delete the rest from both folders. I am thinking of something like:
Sub DelNotFoundFiles()
Dim Folder1 As String, Folder2 As String
Dim FileName1 As Object, FileName2 As Object
Dim Item As Object
Folder1 = "Z:\Path-to the-folder1\"
Folder2 = "Z:\Path-to-the-folder2\"
FileName1 = Dir(Folder1 & "*.xlsx")
FileName2 = Dir(Folder2 & "*.xlsx")
For Each Item In FileName1
If Not FileName2.Exists Then
FileName1.Delete ' Can repeat execution of the code with the folder names switched, but Ideally code differently to delete uncommon files in both folders at the same time
End If
Next
End Sub
Could someone please help fix the template above.
Thank you,
Shawn
I have two folders that contain a number of .xlsx files. Some of the files in Folder1 are also found in Folder2. I want to keep the files that are common in both folders, and delete the rest from both folders. I am thinking of something like:
Sub DelNotFoundFiles()
Dim Folder1 As String, Folder2 As String
Dim FileName1 As Object, FileName2 As Object
Dim Item As Object
Folder1 = "Z:\Path-to the-folder1\"
Folder2 = "Z:\Path-to-the-folder2\"
FileName1 = Dir(Folder1 & "*.xlsx")
FileName2 = Dir(Folder2 & "*.xlsx")
For Each Item In FileName1
If Not FileName2.Exists Then
FileName1.Delete ' Can repeat execution of the code with the folder names switched, but Ideally code differently to delete uncommon files in both folders at the same time
End If
Next
End Sub
Could someone please help fix the template above.
Thank you,
Shawn