compare files in 2 folders

Directlinq

Registered User.
Local time
Today, 09:35
Joined
Sep 13, 2009
Messages
67
Hi what code would i need to check a folder contents to another folder contents, and if any 1 file has the same name then End Sub

Many Thanks
 
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

Many Thanks
 
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
 
I don't know if this is of any help

http://allenbrowne.com/ser-59.html

Choose the List Files to a Table.

I have great success with this.

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.

Many Thanks
 
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
 

Users who are viewing this thread

Back
Top Bottom