Fso.copyfile Error Handling
Contents |
Posts : 6 Scores: 0 Reward points : 0 Joined: 3/14/2006 Status: offline Filesystem object copyfile method error codes Tuesday, March 14, 2006 5:25 AM (permalink) 0 vbs copyfile Hey Everyone, I'm kinda new to scripting but so far I"m doing ok.
Vbscript Error Handling
However, I'm trying to write a routine that will backup one of my database servers and then email me, so far I haev most of it working, but I want to be able to write any errors it gets to a logfile. However, i don't know what the error codes for the copyfile method are. Nor can I seem to find them on the net. I want do something silly like this: fs.CopyFile strSrc1, strDst1, True if err.number <> 0 Then logf.write "Error encountered, the error is...... (Andthen insert what went wrong) Pardon my newness, I'm sure this is a pretty easy thing for some of you gurus :) Thanks in advance!! #1 ebgreen Total Posts : 9274 Scores: 172 Reward points : 0 Joined: 7/12/2005 Status: offline RE: Filesystem object copyfile method error codes Tuesday, March 14, 2006 5:28 AM (permalink) 0 You typically don't need to know what the error codes are. The Err object includes a .Description property that is usually descriptive enough. I do what you are trying something like this: If Err.Number <> 0 Then logf.write "Error encountered while doing FOO - (" & Err.Number & ") - " & Err.Description End If Stop the Help Vampires:http://slash7.com/2006/12/22/vampires/ VB is NOTVB.Net which is NOTVBA which is NOTVBScript #2 mcgyver74 Total Posts : 6 Scores: 0 Reward points : 0 Joined: 3/14/2006 Status: offline RE: Filesystem object copyfile method error codes Tuesday, March 14, 2006 6:30 AM (permalink) 0 Thanks dude, that's exactly waht I am looking for!!!! #3 mcgyver74 Total Posts : 6 Scores: 0 Reward points : 0 Joined: 3/14/2006 Status: offline RE: Filesystem object copyfile method error codes Wednesday, March 15, 2006 3:28 AM (permalink) 0 That's working great. But I do have one more quick Q. is the err.description valid for pro
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 http://www.visualbasicscript.com/Filesystem-object-copyfile-method-error-codes-m32260.aspx 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 http://www.tek-tips.com/viewthread.cfm?qid=424854 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(Er
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: http://www.techrepublic.com/forums/discussions/vbs-error-handling-and-loops/ 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 https://msdn.microsoft.com/en-us/library/e1wf9e7w(v=vs.84).aspx 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 error handling Welcome back, My Profile Log Out Recent 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 fso.copyfile error handling 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 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 tot
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. FileSystemObject FileSystemObject Reference (Windows Scripting) FileSystemObject Methods FileSystemObject Methods CopyFile Method CopyFile Method CopyFile Method Add Method (Folders) BuildPath Method Close Method (FileSystemObject) Copy Method (FileSystemObject) CopyFile Method CopyFolder Method CreateFolder Method CreateTextFile Method Delete Method DeleteFile Method DeleteFolder Method DriveExists Method FileExists Method FolderExists Method GetAbsolutePathName Method GetBaseName Method GetDrive Method GetDriveName Method GetExtensionName Method GetFile Method GetFileName Method GetFileVersion Method GetFolder Method GetParentFolderName Method GetSpecialFolder Method GetStandardStream Method GetTempName Method Move Method MoveFile Method MoveFolder Method OpenAsTextStream Method OpenTextFile Method Read Method ReadAll Method ReadLine Method Skip Method SkipLine Method Write Method (FileSystemObject) WriteBlankLines Method WriteLine Method (FileSystemObject) TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. CopyFile Method Copies one or more files from one location to another.Syntax Copy object.CopyFile ( source, destination[, overwrite] ) ArgumentsobjectRequired. The object is always the name of a FileSystemObject.sourceRequired. Character string file specification, which can include wildcard characters, for one or more files to b