Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm needing help creating or modifying an existing script to scan a network drive and backup files and directory structure based on a lastmodified date. Please help

Could you perhaps be a bit more vague? That way we can ensure no one even knows what you want.
Or, alternatively, you could clarify your post. Specifically, what are you backing up?
From where? To where? How? Compare the modified date to what?Also, we might help you, but you shouldn't rely on us without some token effort on your part. I answer most of the VBScript questions on this board, and I'm moody.

"Could you perhaps be a bit more vague? That way we can ensure no one even knows what you want."
Lol
"Foolproof systems don't take into account the ingenuity of fools."

Sorry, here is the code I've found and modified. It works great with a specific path. What I would like it to do is scan the entire path & sub directories and copy the changed file to a different location keeping the directory structure. Thanks.
Option Explicit
CONST PATH = "c:\test"
Dim strDate_2_Copy, strShare
Dim fso, objFolder, colFiles, objFile, strFolder,strFile
Set fso = CreateObject("Scripting.FileSystemObject")
strDate_2_Copy = now()
strShare = "c:\test2\"
If fso.FolderExists(PATH) Then
Set objFolder = fso.GetFolder(PATH)
Set colFiles = objFolder.Files
Else
Wscript.Echo "Can't find the " & PATH & " folder"
Wscript.Quit
End if
For Each strFile in colFiles
Set objFile = fso.GetFile(strFile)
If DateDiff("d", objFile.DateLastModified, strDate_2_Copy) = 0 Then
fso.CopyFile strFile, strShare, True
Wscript.Echo strFile.Name & ", Mod-Date: " & objFile.DateLastModified & ", copied to " & strShare
End If
Set objFile = Nothing
Next
Wscript.Quit

This should work, but it is untested.
Option ExplicitConst start = "c:\test"
Const dest = "c:\test2\"
Const logName = "c:\test2\log.txt"
Dim fso, log
Set fso = CreateObject("Scripting.FileSystemObject")
Set log = fso.OpenTextFile(logName, 8, True)
log.WriteLine vbNewLine & "Backup started @ " & Now()
DoWork start, dest, Now()
log.WriteLine "Backup ended @ " & Now()
Sub DoWork(dir, dest, modDate)
Dim objFile, objDir
log.WriteLine "DIR: " & dir
If Not fso.FolderExists(dir) Then
log.WriteLine "Can't find the " & dir & " folder"
Exit Sub
End If
With fso.GetFolder(dir)
For Each objFile in .Files
If DateDiff("d", objFile.DateLastModified, modDate) = 0 Then
objFile.CopyFile dest, True
log.WriteLine objFile.Name & ", Mod-Date: " _
& objFile.DateLastModified & ", copied to " & dest
End If
Next
For Each objDir In .Folders
DoWork objDir.Path, des, modDate
Next
End With
End Sub

Thanks for the new script. I changed the Copyfile line and the script works for the starting directory. It gets an error when trying to change directories in the bottom for/next statement. My editor is telling me that the in.folders statment is incorrect. Any Help? Thanks
Option Explicit
Const start = "c:\test\"
Const dest = "c:\test2\"
Const logName = "c:\test2\log.txt"
Dim fso,Logg
Set fso = CreateObject("Scripting.FileSystemObject")
Set logg = fso.OpenTextFile(logName, 8, True)
logg.WriteLine vbNewLine & "Backup started @ " & Now()
DoWork start, dest, Now()
logg.WriteLine "Backup ended @ " & Now()Sub DoWork(dir, dest, modDate)
Dim objFile, objDir
logg.WriteLine "DIR: " & dir
If Not fso.FolderExists(dir) Then
logg.WriteLine "Can't find the " & dir & " folder"
Exit Sub
End If
With fso.GetFolder(dir)
For Each objFile in.Files
if DateDiff("d", objFile.DateLastModified, modDate) = 0 Then
fso.CopyFile objfile,dest, True
'objFile.CopyFile dest, True
logg.WriteLine objFile.Name & ", Mod-Date: " & objFile.DateLastModified & ", copied to " & dest
End If
Next
For Each objDir in.Folders
DoWork objDir.Path, dest, modDate
Next
End With
End Sub

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |