Computing.Net > Forums > Programming > vbscript backup

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vbscript backup

Reply to Message Icon

Name: maristar210vrs
Date: December 20, 2007 at 12:01:57 Pacific
OS: winxp
CPU/Ram: 6ghz/1gb
Product: dell
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: December 20, 2007 at 22:09:54 Pacific
Reply:

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.


0

Response Number 2
Name: tonysathre
Date: December 21, 2007 at 05:56:57 Pacific
Reply:

"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."


0

Response Number 3
Name: maristar210vrs
Date: December 21, 2007 at 08:08:48 Pacific
Reply:

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


0

Response Number 4
Name: Razor2.3
Date: December 21, 2007 at 18:15:44 Pacific
Reply:

This should work, but it is untested.

Option Explicit

Const 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



0

Response Number 5
Name: maristar210vrs
Date: December 26, 2007 at 08:31:51 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: December 27, 2007 at 18:09:08 Pacific
Reply:

Well, I did say it was untested.
Replace .Folders with .SubFolders


0

Response Number 7
Name: maristar210vrs
Date: December 28, 2007 at 11:08:25 Pacific
Reply:

Thanks, I did that and it works.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: vbscript backup

Comparing Files+Folders using VBS www.computing.net/answers/programming/comparing-filesfolders-using-vbs/14112.html

daily log backups www.computing.net/answers/programming/daily-log-backups-/9256.html

Deleting files using VBscript www.computing.net/answers/programming/deleting-files-using-vbscript/12660.html