Hi Everyone

I'm trying find out whether one folder(folder 1) files are exist in another folder(folder 2) or not - if exits then copy that file to another folder(folder 2) - I tried but i'm getting some errors -
Please me on the this

Sub compare()
Dim ofso As Object
Set ofso = CreateObject("Scripting.FileSystemObject")
Dim cSourceDir As Object
'Dim cDestDir As Object
Dim ofile As Object

Set cSourceDir = ofso.GetFolder("C:\folder1")
Const cDestDir = "C:\folder2\"
    
    Set oFolder = ofso.GetFolder(cSourceDir)
   

Dim sdestpath As Object
   For Each ofile In oFolder.Files
         sdestpath = Replace(ofile.Path, cSourceDir, cDestDir, 1, -1, 1)
      If Not ofso.FileExists(sdestpath) Then
         MsgBox ("File missing = " & sdestpath)
          FileCopy "C:\folder1\" & ofile, "C:\folder2\" & ofile
         Wscript.Quit
      End If
   Next
 
   'For Each oSubFolder In oFolder.SubFolders
   '   ScanFolder (oSubFolder)
   'Next

End Sub

Thanks
Thiru