Question : Copy Files From Source Directory To Local Directory Using VBA

In my project, I have one master computer which will post files to several different folders in a project directory. so the common directory might be

\\servername\data\CxFiles
 There will be the following folders that I would want to copy from

\\servername\data\CxFiles\ATR
\\servername\data\CxFiles\IIF
\\servername\data\CxFiles\RIF
\\servername\data\CxFiles\Startup
\\servername\data\CxFiles\ConstructionDwgs
\\servername\data\CxFiles\FPT
\\servername\data\CxFiles\Spec
\\servername\data\CxFiles\FAT

There is a standard file structure on the local machine that has all of those same folders
C:\Commissioning Database\PDFReports\

I would like to be able to click a button in Access, and then update all of those folders.

So if in the master directory you have the following
\\servername\data\CxFiles\ATR\File1.pdf
\\servername\data\CxFiles\ATR\File2.pdf
\\servername\data\CxFiles\ATR\File3.pdf

and locally I have
C:\Commissioning Database\PDFReports\ATR\File1.pdf

I only want to copy File2.pdf and File3.pdf. to the local machine.

I basically just need to mirror whatever information is in the master directory on the local machine.  There may be a situation where File1.pdf was replaced with a newer version and I would like to overwrite the local copy if there is a newer version on the master directory.

Do I need to be looking at a batch script? or can I do this in VBA? or what?

Any help is greatly appreciated.

Thanks

Answer : Copy Files From Source Directory To Local Directory Using VBA

test this codes

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Sub copyFiles()
Dim myFolders(), srcFolder As String, j, pdfFile As String, destFolder As String
destFolder = "C:\Commissioning Database\PDFReports\"
srcFolder = "\\servername\data\CxFiles\"
myFolders = Array("ATR", "IIF", "RIF", "StartUp", "ConstructionsDwgs", "FPT", "Spec", "FAT")
For j = LBound(myFolders) To UBound(myFolders)
    pdfFile = Dir(srcFolder & myFolders(j) & "\*.pdf")
    While pdfFile <> ""
        FileCopy srcFolder & myFolders(j) & "\" & pdfFile, destFolder & myFolders(j) & "\" & pdfFile
        pdfFile = Dir
    Wend
Next
End Sub
Random Solutions  
 
programming4us programming4us