how to copy recently modified files

Joined
Aug 1, 2007
Messages
1
Reaction score
0
Hi this is ramana, i am very new this forum, if i posted wrong forum pls excuse, please help sir,my question i have two SeverA and ServerB every day update the files in serverA means adding the files, what is my question is, recently updated files should be copy to ServerB how to do this usinf WSH please help me sir,

i have tried like this, this the code is in WSH
vbscript.

////////////////////////////////////////////////////////////////////
This is the sample script but its giving some errors
///////////////////////////////////////////////////////////////////
'On Error Resume Next

'Compare and copy Changed Files Script // 'Purpose: Compares local file structure with a source location and downloads changed or new items //'CAUTION: This script only works for TWO folder levels (ie main level and one subfolder level).

'Can easily be updated to include further subfolders by duplicating the loop statements

'declare filesystemobject

Option Explicitly

'Set variables

Dim fso,sourcetoplevelfolder,localtoplevelfolder,sourcetoplevelpath

Dim sourcestring,localstring

Set fso = CreateObject("Scripting.FileSystemObject")

Set objNetwork = WScript.CreateObject("WScript.Network")

objNetwork.MapNetworkDrive
"z:", "\\19.16.2.10\c$\test","True","udd","@@g0t"

sourcetoplevelpath = "\\19.16.2.10\c$\test" '"mysopurcepath" 'enter the folder path (preferably UNC) of the folder that contains the SOURCE files.

'Set FSO = CreateObject("Scripting.FileSystemObject")

Set sourcetoplevelfolder = fso.GetFolder("\\19.16.2.10\c$\test")

Set localtoplevelpath =fso.GetFolder("c:\abc") 'enter the folder path (preferably UNC) of the folder that contains the DESTINATION files.

'Set fso = CreateObject("Scripting.FeSystemObject")

'Set local folder and declare subfolders - create it if it doesn't exist.

Set localtoplevelfolder = fso.GetFolder(localtoplevelpath)

'loop through top level of local folder and check items

For Each file In sourcetoplevelfolder.Files

'check for existance of the local file - if it exists, compare - if not, copy to local.

If fso.fileExists(localtoplevelpath & "\" & file.name) Then

Set localfile = fso.getfile(localtoplevelpath & "\" & file.name)

'create strings for comparison - include parentfolder items to ensure uniqueness.

sourcestring = file.parentfolder.name & " " & file.name & " " & file.datelastmodified

localstring = localfile.parentfolder.name &
" " & localfile.name & " " & localfile.datelastmodified

'compare strings. If different, then update file. If equal, do nothing and iterate to to next file.

If localstring <> sourcestring Then

fso.CopyFile sourcetoplevelpath &
"\" & file.name, localtoplevelpath & "\" & file.name, True

Else

fso.CopyFile sourcetoplevelpath & "\" & file.name, localtoplevelpath & "\" & file.name, True

End If



'Next

'loop through contents of subfolders and do as above.

For Each folder In sourcetoplevelfolder.SubFolders



If fso.folderexists(localtoplevelpath & "\" & folder.name) Then

Set sourcefolder = fso.getfolder(folder.path)

Else

fso.createfolder localtoplevelpath & "\" & folder.name

Set sourcefolder = fso.getfolder(folder.path)

End If



' For Each file In folder.files



Set sourcefile = fso.getfile(file.path)

MsgBox sourcefile



If fso.fileExists(localtoplevelfolder & "\" & file.name) Then

Setlocalfolder = fso.getfolder(localtoplevelpath & "\" & folder.name)

Set localfile = fso.getfile(localtoplevelfolder & "\" & file.name)

sourcestring = file.parentfolder.name &
" " & file.name & " " & file.datelastmodified

MsgBox sourcestring

localstring = localfile.parentfolder.name &
" " & localfile.name & " " & localfile.datelastmodified

MsgBox localstring

If localstring <> sourcestring Then fso.CopyFile sourcefile, localtoplevelpath & "\" & file.name,True

Else

fso.Copyfilesourcefile, localtoplevelpath & "\" & folder.name & "\" & file.name, True

End If

Next

'Next

End If

'reclaim memory from object variables

Set sourcetoplevelfolder = Nothing

Set
localtoplevelfolder = Nothing

Set
sourcefile = Nothing

Set
localfile = Nothing

Set
fso = Nothing

objnetwork.RemoveNetworkDrive "Z:"

WScript.Echo " Drive Closed:: check: "

Next

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top