Createobject Scripting.filesystemobject Error Handling
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and vbscript error handling policies of this site About Us Learn more about Stack Overflow the
Fso.copyfile Error Handling
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags vbscript on error exit Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only on error goto 0 takes a minute: Sign up Error handling in vbscript? up vote 2 down vote favorite There is some old legacy vbscript code we have that needs some sort of error handing in it. Having never used vbscript before, I'm at a total loss. Here is the code: set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0") objBL.ConnectionString = "connectionstring" objBL.KeepIdentity = false objBL.ErrorLogFile = "E:\code\Acquity\WebOrderImport\logs\error.log" Set
On Error Resume Next
fso = CreateObject("Scripting.FileSystemObject") Set parentfolder = fso.GetFolder("E:\textdata\Acquity\AcquityWebOrders") Set logfile = fso.OpenTextFile("E:\code\Acquity\WebOrderImport\logs\import.log",8) count = 0 For each folder in parentfolder.subfolders logfile.writeline count & " files" logfile.writeline "Processing " & folder.name & " ***********************************" & now() count = 1 For Each file in folder.files If left(file.name,6) = "Order_" then If left(file.name,13) = previous then logfile.writeline "!!!!! SKIPPING file " & file.name & "!!!!! DUPED ORDER ID" Else logfile.writeline "reading " & file.name objBL.Execute "E:\code\Acquity\WebOrderImport\acq_WebOrder_import.xsd", file.path count=count+1 End If previous = left(file.name,13) End If Next Next set objBL=Nothing logfile.writeline "Done!" Set logfile = nothing Set parentfolder = nothing set fso = nothing I'm pretty sure this line: bjBL.Execute "E:\code\Acquity\WebOrderImport\acq_WebOrder_import.xsd", file.path keeps throwing exceptions, and I need the code to keep running when it hits an error, rather than stopping. How can I do this? scripting vbscript error-handling share|improve this question asked Jan 9 '12 at 17:12 broke 2,666103364 add a comment| 3 Answers 3 active oldest votes up vote 5 down vote accepted To ignore errors, add On Error Resume Next before the part that can cause them. To disable the effect of "resume
United States Australia United Kingdom Japan Newsletters Forums Resource Library Tech Pro Free Trial Membership Membership My Profile People Subscriptions My stuff Preferences Send a message Log Out TechRepublic Search GO Topics: CXO Cloud Big Data Security Innovation Software Data Centers Networking Startups Tech & Work All Topics Sections: Photos Videos All Writers Newsletters Forums Resource Library Tech Pro Free Trial Editions: US United States Australia United Kingdom Japan Membership Membership My Profile People Subscriptions My stuff Preferences Send a message Log Out TechRepublic | Forums | Web Development Web Development Register Now or Log In to post Welcome back, My Profile Log Out Recent http://stackoverflow.com/questions/8792337/error-handling-in-vbscript Activity FAQs Guidelines Question 0 Votes Locked VBS Error Handling and Loops By alxcsby · 6 years ago I'm trying to make a script that will allow me to copy a specified file to a predefined list of PCs (C:\PCs.txt). I'd like to have this script write to a separate file (C:\MassCopyError.txt) for each PC that fails, then notify me when it's finished.So far, I'm able to copy the file http://www.techrepublic.com/forums/discussions/vbs-error-handling-and-loops/ without error, and I'm able to write the first PC that fails, but I can't get it to write more than one error, and I can't get it to notify me when it's finished. It just copies, notifies me there's been one error, logs one error, and closes out. Any ideas what I'm doing wrong? I know this would be easier in pure VB or even C++, but I'm trying to do it in VBS. On Error Resume NextConst ForReading = 1Const ForAppending = 8Const OverwriteExisting = TRUESet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("C:\PCs.txt", ForReading)dim currentFileLocationdim newFileLocationcurrentFileLocation=InputBox("What is the file's current location?", "Current File Location")newFileLocation=InputBox("Where would you like the file to go?", "New File Location")Do Until objFile.AtEndOfStream On Error Resume Next strComputer = objFile.ReadLine strRemoteFile = "\\" & strComputer & "\" & newFileLocation & "\" objFSO.CopyFile currentFileLocation, strRemoteFile, OverwriteExistingLoop If Err.Number <> 0 Then wscript.Echo "An error has occurred. Please see C:\MassCopyError.txt for details" Set objFile = objFSO.CreateTextFile("C:\MassCopyError.txt") Set objFile = obj.FSO.OpenTextFile ("C:\MassCopyError.txt", ForAppending, True) objFile.WriteLine(strComputer&vbCrLf) objFile.Close Err.Clear End Ifwscipt.Echo "MassCopy has finished copying files."
Share Flag This conversation is currently closed to new comments. 2 total posts (Page 1 of 1) + Follow this Discussion · | Thread display: Collapse - | Expand + All Answers
Microsoft Tech Companion App Microsoft Technical Communities Microsoft Virtual Academy Script Center Server and Tools Blogs TechNet Blogs TechNet Flash Newsletter TechNet Gallery https://technet.microsoft.com/en-us/library/ee692852.aspx TechNet Library TechNet Magazine TechNet Subscriptions TechNet Video TechNet Wiki Windows Sysinternals Virtual Labs Solutions Networking Cloud and Datacenter Security Virtualization Downloads Updates Service Packs Security Bulletins Windows Update Trials Windows Server 2012 R2 System Center 2012 R2 Microsoft SQL Server 2014 SP1 Windows 8.1 Enterprise See all trials » Related Sites Microsoft Download Center TechNet Evaluation Center error handling Drivers Windows Sysinternals TechNet Gallery Training Training Expert-led, virtual classes Training Catalog Class Locator Microsoft Virtual Academy Free Windows Server 2012 courses Free Windows 8 courses SQL Server training Microsoft Official Courses On-Demand Certifications Certification overview MCSA: Windows 10 Windows Server Certification (MCSE) Private Cloud Certification (MCSE) SQL Server Certification (MCSE) Other resources TechNet Events Second shot createobject scripting.filesystemobject error for certification Born To Learn blog Find technical communities in your area Support Support options For business For developers For IT professionals For technical support Support offerings More support Microsoft Premier Online TechNet Forums MSDN Forums Security Bulletins & Advisories Not an IT pro? Microsoft Customer Support Microsoft Community Forums United States (English) Sign in Home Library Wiki Learn Gallery Downloads Support Forums Blogs We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Script Center VBScript Doctor Scripto’s Script Shop Doctor Scripto’s Script Shop To Err Is VBScript – Part 1 To Err Is VBScript – Part 1 To Err Is VBScript – Part 1 Bring in da Subs, Bring in da Funcs - Building scripts with procedures Controlling pest-ware with asynchronous event monitoring Greg Smacks Down Procedures Inventorying Windows XP Service Packs - Part 1 Inventorying Windows XP Service Packs - Part 2 Inventorying Windows XP Service Packs - Part 3 - Scripting the Rollout It's 2 a.m. Do you know whe