The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
Trouble getting vb script to work backing up files.
Discuss Trouble getting vb script to work backing up files. in the Visual Basic Programming forum on Dev Shed. Trouble getting vb script to work backing up files. Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 5th, 2012, 10:41 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 2
Time spent in forums: 1 h 4 m 10 sec
Reputation Power: 0
|
|
|
Trouble getting vb script to work backing up files.
Hi,
I'm having issues at this line getting script to run correctly.
Else
For Each oStart In oSub.Files
Here's full code! Any ideas?
'==========================================================================
'Backup-Data.VBS
'AUTHOR: Don Savage
'DATE: 05.29.2012
'COMMENT: Copys All known data types to Cab File for easy access
'==========================================================================
DIM oFSO, oSub, oStart, sIndent, oLog, oFile, sLogName, oList, oShell, sCwd, aExtensions, sDate, sRun, sTarget
' Array contains uppercase File Extension Names to be backed up
aExtensions = Array("LOG", "DOC", "XLS", "MP3", "WMA", "IFM", "TXT", "DAT", "PDF", "MDB", "SQL", "TBK", "SIG", "MSG", "GRA", "IPK", "IXL", "QDF", "JPG", "JPEG", "BMP", "MAC", "ZWS", "ZCC", "DGN", "VSD", "PSD", "RTF", "DOT", "MPP", "PPT", "PPS", "PST", "SCD", "PAB", "LLW", "EML")
Set oShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDate = Month(Now) & "-" & Day(Now) & "-" & Year(Now)
sTarget = ".\BackUp_" & sDate
sCwd = "C:\"
If Wscript.Arguments.Count<> 0 Then
sCwd = Wscript.Arguments(0)
End If
If Wscript.Arguments.Count>1 Then
sTarget = Wscript.Arguments(1)
End If
sLogName = sTarget&".Log"
If oFSO.FileExists(sTarget) Then
oFSO.DeleteFile(sTarget)
End If
Set oLog = oFSO.CreateTextFile(sLogName, 1)
Set oStart = oFSO.GetFolder(sCwd)
oShell.Popup "Scanning for Files", 3
CollectFiles "", oStart, oLog
oShell.Popup "Archiving Files to " + sTarget, 1
oLog.WriteLine sLogName
oLog.Close
ArchiveFiles
oFSO.DeleteFile(sLogName)
oShell.Popup "Done", 5
Sub CollectFiles (sIndent, oStart, oOutFile )
If iCount = 1 Then
If oFSO.GetParentFolderName(oStart) = "" Then
For Each oFile in oStart.Files
For x = 0 to Ubound(aExtensions)
If UCase(oFSO.GetExtensionName(oFile)) = aExtensions(x) Then
oLog.WriteLine oFile.Path
End If
Next
Next
End If
End If
For Each oSub In oStart.SubFolders
' Folders Selected to prevent errors from permissions and wasted space.
If oSub.Name = "System Volume Information" Or oSub.Name = "RECYCLER" Or oSub.Name = "Oracle" Or oSub.Name = "Common Files" Or oSub.Name ="Temporary Internet Files" Or oSub.Name ="WINNT" Or oSub.Name ="I386" Or oSub.Name ="Documents and Settings" Or oSub.Name ="Uninstall Information" Or oSub.Name ="WindowsUpdate" Or oSub.Name ="Backup" Then
Else
For Each oStart In oSub.Files
For x = 0 To Ubound(aExtensions)
If UCase(oFSO.GetExtensionName(oFile)) = aExtensions(x) Then
oLog.WriteLine chr(34) & oFile.Path & chr(34)
End If
Next
Next
If iCount <> oStart.SubFolders.Count Then
CollectFiles sIndent & " ", oSub, oLog
Else
CollectFiles sIndent & " ", oSub, oLog
End If
End If
iCount = iCount + 1
Next
End Sub
Sub ArchiveFiles()
sRun = "cabarc -p n "& sTarget & ".Cab @" & sLogName
oShell.Run sRun, 1, true
End Sub
|

July 5th, 2012, 08:09 PM
|
|
|
|
Please use the forum CODE tags around posted code.
Do you get errors?
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
|

July 6th, 2012, 02:53 PM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 2
Time spent in forums: 1 h 4 m 10 sec
Reputation Power: 0
|
|
The windows script host error is at line 61 showing error: Object required: 'oStart'
Line 61= If iCount <> oStart.SubFolders.Count Then
The purpose of the script is to backup all listed known file extensions and write them to a cab file using cabarc.exe.
Code:
'==========================================================================
'Backup-Data.VBS
'AUTHOR: Don Savage
'DATE: 05.29.2012
'COMMENT: Copys All known data types to Cab File for easy access
'==========================================================================
DIM oFSO, oSub, oStart, sIndent, oLog, oFile, sLogName, oList, oShell, sCwd, aExtensions, sDate, sRun, sTarget
' Array contains uppercase File Extension Names to be backed up
aExtensions = Array("LOG", "DOC", "XLS", "MP3", "WMA", "IFM", "TXT", "DAT", "PDF", "MDB", "SQL", "TBK", "SIG", "MSG", "GRA", "IPK", "IXL", "QDF", "JPG", "JPEG", "BMP", "MAC", "ZWS", "ZCC", "DGN", "VSD", "PSD", "RTF", "DOT", "MPP", "PPT", "PPS", "PST", "SCD", "PAB", "LLW", "EML")
Set oShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDate = Month(Now) & "-" & Day(Now) & "-" & Year(Now)
sTarget = ".\BackUp_" & sDate
sCwd = "C:\"
If Wscript.Arguments.Count<> 0 Then
sCwd = Wscript.Arguments(0)
End If
If Wscript.Arguments.Count>1 Then
sTarget = Wscript.Arguments(1)
End If
sLogName = sTarget&".Log"
If oFSO.FileExists(sTarget) Then
oFSO.DeleteFile(sTarget)
End If
Set oLog = oFSO.CreateTextFile(sLogName, 1)
Set oStart = oFSO.GetFolder(sCwd)
oShell.Popup "Scanning for Files", 3
CollectFiles "", oStart, oLog
oShell.Popup "Archiving Files to " + sTarget, 1
oLog.WriteLine sLogName
oLog.Close
ArchiveFiles
oFSO.DeleteFile(sLogName)
oShell.Popup "Done", 5
Sub CollectFiles (sIndent, oStart, oOutFile )
If iCount = 1 Then
If oFSO.GetParentFolderName(oStart) = "" Then
For Each oFile in oStart.Files
For x = 0 to Ubound(aExtensions)
If UCase(oFSO.GetExtensionName(oFile)) = aExtensions(x) Then
oLog.WriteLine oFile.Path
End If
Next
Next
End If
End If
For Each oSub In oStart.SubFolders
' Folders Selected to prevent errors from permissions and wasted space.
If oSub.Name = "System Volume Information" Or oSub.Name = "RECYCLER" Or oSub.Name = "Oracle" Or oSub.Name = "Common Files" Or oSub.Name ="Temporary Internet Files" Or oSub.Name ="WINNT" Or oSub.Name ="I386" Or oSub.Name ="Documents and Settings" Or oSub.Name ="Uninstall Information" Or oSub.Name ="WindowsUpdate" Or oSub.Name ="Backup" Then
Else
For Each oStart In oSub.Files
For x = 0 To Ubound(aExtensions)
If UCase(oFSO.GetExtensionName(oFile)) = aExtensions(x) Then
oLog.WriteLine chr(34) & oFile.Path & chr(34)
End If
Next
Next
If iCount <> oStart.SubFolders.Count Then
CollectFiles sIndent & " ", oSub, oLog
Else
CollectFiles sIndent & " ", oSub, oLog
End If
End If
iCount = iCount + 1
Next
End Sub
Sub ArchiveFiles()
sRun = "cabarc -p n "& sTarget & ".Cab @" & sLogName
oShell.Run sRun, 1, true
End Sub
|

July 6th, 2012, 10:08 PM
|
|
|
|
Nothing leaps off the page at me. The error means your code assumed an instantiated object but the object doesn't exist when you try to use it.
Do you have any "on error resume next" in some code you haven't shown? That statement can cause vbscript to basically ignore errors and continue without any error message.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|