Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overwriting files from two directories

Status
Not open for further replies.

KM8888

Programmer
Nov 21, 2011
69
US
Hi all,

I have pilfered through a lot of posts but can't seem to combine exactly what I'm trying to do. I have a bit of code here but basically, instead of the .txt files I want it to cycle through every file in each folder and match them against each other. If the file doesn't exist in the folder I want to overwrite to it would simply just copy it over, if the date of the file is newer in the LocalFile folder than it is in the ServerFile folder than it will overwrite it into the ServerFile folder.

I know there are tweaks needed to this, probably pointing to the specific folders and some looping but I'm not exactly sure of the syntax, if anybody has any direction it is greatly appreciated! Thanks :)

Code:
Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objLocalFile = objFSO.GetFile("c:\scripts\test.txt")
dtmLocalDate = objLocalFile.DateLastModified

Set objServerFile = objFSO.GetFile("\\source\public\test.txt")
dtmServerDate = objServerFile.DateLastModified

If dtmLocalDate < dtmServerDate Then
    objFSO.CopyFile objServerFile.Path, objLocalFile.Path, OverwriteExisting
End If
 
Thanks for the reply guys. Jges, unfortunately I was looking to utilize a script so I could run it automatically on someone else's PC so downloading a program isn't the most feasible.

Thanks
 
Then look into Geates' suggestion. Here is an faq to get you started on both recursion, and traversing files / folders.
faq329-5515
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top