#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep 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
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,449
    Rep Power
    4539
    Please use the forum CODE tags around posted code.

    Do you get errors?
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep 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
  6. #4
  7. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,449
    Rep Power
    4539
    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.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo