You could loop through the contents of the first folder and test that each file does not exist in the second folder using FileSystemObject.FileExists("filename")
Can somebody tel me why this code does not work please.
It scans through a directory looking at each .mpg file, which works but when i add the bit in bold it loops through to the same file forever.
because i then want to see if that file exists in a folder.
Code:
MsgBox "checking files that already exits"
Dim MyFile As String, Sep As String
Dim oFSO, sFileName
Dim sDoc As String
Dim sPath As String
MyFile = Dir("D:\" & "*.mpg")
Do While MyFile <> ""
[B]sPath = "F:\MediaLib\Video\"
If (Dir(sPath & MyFile) > "") Then
MsgBox "Videos on this disc have already been uploaded to this system"
Exit Sub
End If[/B]
MyFile = Dir()
Loop
MsgBox "continue"
Exit Sub
Right take 2. This code works but if there is a file on the F:\MediaLib\Video\ named the same as on the d:\, but if there is a file in F:\MediaLib\Video\ that is not on the d:\. The whole application stops responding.
Code:
Sub Test()
Dim Folder1Array()
ReDim Folder1Array(0)
MsgBox "checking files that already exits"
Dim MyFile As String, Sep As String
Dim oFSO, sFileName
Dim sDoc As String
Dim sPath As String
Dim Uploaded As Boolean
MyFile = Dir("D:\" & "*.mpg")
Do While MyFile <> ""
ReDim Preserve Folder1Array(UBound(Folder1Array) + 1)
Folder1Array(UBound(Folder1Array)) = MyFile
MyFile = Dir()
Loop
sPath = "F:\MediaLib\Video\"
MyFile = Dir(sPath & "*.mpg")
Uploaded = False
Do While MyFile <> ""
For N = 1 To UBound(Folder1Array)
If Folder1Array(N) = MyFile Then
Uploaded = True
Exit Do
End If
Next N
Loop
If Uploaded = True Then
MsgBox "Videos on this disc have already been uploaded to this system"
End If
End Sub
Is there any way around this?
Please if anybody can help me
Many Thanks
Basically it gets the full path name into a table record for each file. From there you do whatever you like with it in Access so it should be easy to check which records match. If you were to have the file names from two folders into one table then you could to a duplicate check.
Thank you for your help but i really need to be able to do this purely in vba the previous code is so close to what i want to do. If a vba genius out there could advise me i would be eternally greatful.
You forgot to move to the next file in your last loop so if the first file on F-drive was not on D-drive, then you created an endless loop.
Code:
Do While MyFile <> ""
For N = 1 To UBound(Folder1Array)
If Folder1Array(N) = MyFile Then
Uploaded = True
Exit Do
End If
[B]MyFile = Dir()[/B]
Next N
Loop