Error traping
- From: ickleric <home@xxxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 06:38:47 -0700
I have this script below which copies a few folders to a network share
on a server. What i'd like to do it add something so that it logs any
errors that it comes across, e.g. if it can't copy a file because its
in use it would log it then move on to the next file/folder.
Script:
'on error resume next
'Declarations
Set fso = WScript.CreateObject("Scripting.FileSystemObject") 'Standard
File System Object
Set WshNetwork = WScript.CreateObject("WScript.Network") 'Standard
Network Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\documents and settings")
computername=wshNetwork.computername
Outlook = "\Local Settings\Application Data\Microsoft\Outlook"
Set colSubfolders = objFolder.Subfolders
Dim response
BackupDriveLetter = "\\server\share\" 'Where it backs up to.
'Asks to start the backup
response = MsgBox("Would you like to backup the local profiles?", 36,
"Backup Profiles?")
If response = vbYes Then
'BackupDriveLetter = InputBox("Enter backup path")
WScript.Echo "Backup Starting...."
StartBackup() 'Start main Subroutine
Elseif response = vbNo Then
WScript.Echo "Backup Cancelled!"
End If
'Main Program
Sub StartBackup()
objFSO.CreateFolder(BackupDriveLetter & computername) 'Create unique
folder
For Each objSubfolder in colSubfolders
objFSO.CreateFolder(BackupDriveLetter & computername & "\" &
objSubfolder.name ) 'Create Unique folder
If objFSO.FolderExists("C:\Documents and Settings\" &
objSubfolder.Name & "\desktop") Then
objFSO.CopyFolder "C:\Documents and Settings\" & objSubfolder.Name &
"\Desktop" , BackupDriveLetter & computername & "\" &
objSubfolder.Name & "\Desktop" , True
Else
End If
If objFSO.FolderExists("C:\Documents and Settings\" &
objSubfolder.Name & "\My Documents") Then
objFSO.CopyFolder "C:\Documents and Settings\" & objSubfolder.Name &
"\My Documents" , BackupDriveLetter & computername & "\" &
objSubfolder.Name & "\My Documents" , True
Else
End If
If objFSO.FolderExists("C:\Documents and Settings\" &
objSubfolder.Name & "\Favorites") Then
objFSO.CopyFolder "C:\Documents and Settings\" & objSubfolder.Name &
"\Favorites" , BackupDriveLetter & computername & "\" &
objSubfolder.Name & "\Favorites" , True
Else
End If
If objFSO.FolderExists ("C:\Documents and Settings\" &
objSubfolder.Name & Outlook) Then
objFSO.CopyFolder ("c:\Documents and Settings\" & objSubfolder.Name &
outlook) , (BackupDriveLetter & computername & "\" & objSubfolder.Name
& "\Outlook")
Else
End If
Next
wscript.Echo "Backup Complete: Please check backup folder to ensure
backup was successful"
End Sub
.
- Follow-Ups:
- Re: Error traping
- From: MikeD
- Re: Error traping
- Prev by Date: Re: DAO and VB
- Next by Date: Re: Storing variables with Random Files
- Previous by thread: Event Logging Tool?
- Next by thread: Re: Error traping
- Index(es):
Relevant Pages
|