Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 5th, 2012, 10:41 AM
djsav djsav is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 djsav User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old July 5th, 2012, 08:09 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,237 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 43 m 55 sec
Reputation Power: 4445
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

Reply With Quote
  #3  
Old July 6th, 2012, 02:53 PM
djsav djsav is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 djsav User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old July 6th, 2012, 10:08 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,237 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 43 m 55 sec
Reputation Power: 4445
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Trouble getting vb script to work backing up files.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap