Filesystemobject Error Handling
Contents |
here for a quick overview of the site Help Center fso.copyfile error handling Detailed answers to any questions you might have Meta
Vbscript Copyfile Error Handling
Discuss the workings and policies of this site About Us Learn more about Stack Overflow vbs copyfile the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Vbscript Error Handling
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 takes a minute: Sign up Error handling in vbscript? up vote 2 down vote favorite There is some old legacy vbscript code on error resume next 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 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
(עברית)المملكة العربية السعودية (العربية)ไทย (ไทย)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語) HomeLibraryLearnDownloadsRepositoryCommunityForumsBlog Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: VBS Error Handling with a Do Until Loop Scripting > The Official Scripting Guys Forum! Question 0 Sign in to vote VBS Error Handling and Loops 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 http://stackoverflow.com/questions/8792337/error-handling-in-vbscript 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 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 https://social.technet.microsoft.com/Forums/scriptcenter/en-US/49eaa9f5-8af1-4a3d-8799-b8becf56b072/vbs-error-handling-with-a-do-until-loop?forum=ITCG 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 Next
Const ForReading = 1
Const ForAppending = 8
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\PCs.txt", ForReading)
dim currentFileLocation
dim newFileLocation
currentFileLocation=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, OverwriteExisting
Loop
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.
is meant to assist coders in figuring out how errors in FSO should be handled. General There are several macros defined for error handling (see globalincs/pstypes.h). One of the 1st concepts to understand is that some errors http://www.hard-light.net/wiki/index.php/FSO_Error_Handling in trigger in DEBUG builds, others occur in both DEBUG and RELEASE. Most of these can be used anywhere within the FSO codebase. Name In Release? Description mprintf(( printf-formatted-message-needs-\n )); No Prints text to fs2_open.log Generally http://www.tek-tips.com/viewthread.cfm?qid=424854 used for issues that a modder/coder should know about, but not a player Warning: Dynamically allocates memory (SCP_string) so don't use it inside memory management functions nprintf(( TYPE, printf-formatted-message-needs-\n )); No Like mprintf, but output error handling is conditional on TYPE being selected in a debug_filter.cfg Used for verbose logging that would otherwise clog up the fs2_open.log Warning( LOCATION, printf-formatted-message ); No Something has gone wrong, but either it's recoverable or it may not be critical. FSO continues to execute. On Windows, pops up a message box that must be closed by the player. Generally should be used for asset issues not coding issues. The 1st argument, LOCATION is copyfile error handling required verbatim WarningEx( LOCATION, printf-formatted-message ); No Same as warning, except it will only trigger if the command line param "-extra_warn" is set Error( LOCATION, printf-formatted-message ); Yes Something has gone horribly wrong and it's not "safe" to continue. FSO exits. On Windows, outputs a stack trace (symbol may/may not be present depending on how FSO was compiled... I think...) Generally should be used for asset issues not coding issues. The 1st argument, LOCATION is required verbatim Assert( statement ); No Require that a statement be true Generally used to catch coding errors (e.g. input pointers are not-NULL) Not recommended because the output is very terse, use Assertion where-ever possible instead Assertion( statement, printf-formatted-message-needs-\n ); No Same as Assert, except more verbose & *recommended* Verify(??? ); Yes Like an Assert, but works in both Release & Debug VerifyEx(??? ); Yes Same as Verify, except it will only trigger if the command line param "-extra_warn" is set Int3(); No very old, don't add any more of these to FSO On Windows it stops execution and gives a coder the chance to attach a debugger On other platforms it acts like an Error LUA Scripting While all the FSO error handling can be used in LUA, it's preferred to use the following where possible. In pa
Join INTELLIGENT WORK FORUMSFOR COMPUTER PROFESSIONALS Log In Come Join Us! Are you aComputer / IT professional?Join Tek-Tips Forums! Talk With Other Members Be Notified Of ResponsesTo Your Posts Keyword Search One-Click Access To YourFavorite Forums Automated SignaturesOn Your Posts Best Of All, It's Free! Join Us! *Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting Guidelines Promoting, selling, recruiting, coursework and thesis posting is forbidden.Tek-Tips Posting Policies Jobs Jobs from Indeed What: Where: jobs by Link To This Forum! Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.Just copy and paste the BBCode HTML Markdown MediaWiki reStructuredText code below into your site. VBScript Forum at Tek-Tips HomeForumsProgrammersLanguagesVBScript Forum Checking status of a fso.movefile, fso.copyfile etc thread329-424854 Forum Search FAQs Links MVPs Checking status of a fso.movefile, fso.copyfile etc Checking status of a fso.movefile, fso.copyfile etc uprichard (Programmer) (OP) 10 Dec 02 12:20 I have a script that I use to perform filesystem functions.Is there anyway to check the status that comes back from the call?I know I could do a check to see that a new file exists after a copy and that the file does not exist after a delete etc, but that seams very long approach.Thanks for any help.Set fso = CreateObject("Scripting.FileSystemObject")Select Case Action_ValueCase "move"fso.MoveFile Source_Value, Dest_ValueCase "rmdir"fso.DeleteFolder Source_Value, TRUECase "mkdir"fso.DeleteFolder Source_Value, TRUECase "delete"fso.DeleteFile Source_Value, TRUECase "copy"fso.CopyFile Source_Value, Dest_ValueCase Elsemsgbox "Invalid arg"End Select RE: Checking status of a fso.movefile, fso.copyfile etc dilettante (MIS) 10 Dec 02 16:25 You end up doing something like:Set fso = CreateObject("Scripting.FileSystemObject")On Error Resume NextSelect Case Action_ValueCase "move"fso.MoveFile Source_Value, Dest_Value::Case Elsemsgbox "Invalid arg"End SelectIf Err.Number <> 0 ThenMsgBox Action_Value & " error #" & CStr(Err.Number) & _" (" & Err.Description & ")"'Other stuff to handle errorErr.ClearEnd IfOn Error GoTo 0Of course you can get as fancy with your error handling as you choose.Better read up on VBScript error processing.I suggest:http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/728/msdncompositedoc.xml&frame=true Red Flag This Post Please let us know here why this post is inappropriate. Reasons such as off-topic,