Objfso.copyfile Error Handling
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more vbs copyfile about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users vbscript error handling Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBscript: Verifying that a file has been completely copied/error handling up vote 0 down vote favorite 1 I am trying to add something to my script that will let me know if a file that I am copying has been fully copied. Basically I am zipping up a bunch of files and then sending them to a mapped drive on the network. Then I have my script deleting the files in the original location once they have been successfully copied over. The script works perfectly fine but I just need to add in some error handling that will let me know if the copy was not completed successfully. I have never used any error handling in vbscript as I am only about a week into this so any help would be greatly appreciated. Let me know if I need to explain anything more in depth. My script can be found below: Option Explicit Dim sDirectoryPath, sDestinationPath, sOutputFilename, Shell, sFileExt, sFilePrefix shell = WScript.CreateObject("WScript.Shell") 'Specify Directory Path where files to be zipped are located 'Specify destination for zipped files 'Specify file extension name to look for 'Specify prefix of filename to look for sDirectoryPath = "C:\Testscripts\" sDestinationPath = "C:\Script\files\outzips\" sOutputFilename = shell.ExpandEnvironmentStrings("%COMPUTERNAME%") sFileExt = ".evtx" sFilePrefix = "Archive*" Dim Command, RetVal Dim d : d = Date() Dim dateStr : dateStr = Year(d) & "-" & Right("00" & Month(d), 2) & "-" & Right("00" & Day(d), 2) Dim t : t = Time() Dim timeStr: timeStr = Hour(t) & "-" & Right("00" & Minute(t), 2) & "-" & Right("00" & Second(t), 2) Command = """C:\Program Files\7-zip\7z.exe"" a " & sDestinationPath & sOutputFilename & "-" & dateStr & "-" & timeStr & ".zip " & sDirectoryPath & sFilePrefix & sFileExt RetVal = Shell.Run(Command,0,true) Wscript.Sleep 2000 Dim objFso Set objFSO = CreateObject("Scripting.FileSystemObject") 'Copy files from one path to another objFSO.CopyFile "C:\script\files\outzips\*.zip" , "G:\CopyTestFolder\" If err.Number <> 0 Then WScript.Echo "An error occured copying this file, re-attempt copy" Else WScript.Echo "No errors occured, copy successful" End If On Error
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBScript Catching Erroring Varialble Value up vote 0 down vote favorite I have a http://stackoverflow.com/questions/11300070/vbscript-verifying-that-a-file-has-been-completely-copied-error-handling VB Script (.vbs file) that is just a simple directory listing of a drive. It will the base of a drive back up script. But when running it as it is below, I am getting a Permission Denied error on some folder. What I need to find is what that folder is so I can figure out what the problem is with the folder. The line that is giving the error http://stackoverflow.com/questions/2659071/vbscript-catching-erroring-varialble-value is "For Each TempFolder In MoreFolders". So what I am trying to figure out is how to WScript.Echo the current path (objDirectory) if there is an error. I am not sure if it matters much, but just in case, the error that I am getting is Permission Denied 800A0046 on line 12. So some folder, I do not know which one, is not letting me look inside. Set WSShell = WScript.CreateObject("WScript.Shell") Set objFSO = CreateObject ("Scripting.FileSystemObject") Dim FolderArr() FolderCount = 0 TopCopyFrom = "G:\" Sub WorkWithSubFolders(objDirectory) Set MoreFolders = objDirectory.SubFolders 'The next line is where the error occurs (line 12) For Each TempFolder In MoreFolders FolderCount = FolderCount + 1 ReDim Preserve FolderArr(FolderCount) FolderArr(FolderCount) = TempFolder.Path ' WScript.Echo TempFolder.Path WorkWithSubFolders(TempFolder) Next End Sub ReDim Preserve FolderArr(FolderCount) FolderArr(FolderCount) = TopCopyFrom Set objDirectory = objFSO.GetFolder(TopCopyFrom) WorkWithSubFolders(objDirectory) Set objDirectory = Nothing WScript.Echo "FolderCount = " & FolderCount WScript.Sleep 30000 Set objFSO = Nothing Set WSShell = Nothing vbscript error-handling filesystemobject share|improve this question asked Apr 17 '10 at 16:18 Soren 5324810 What happens when you uncomment the line you have in there, with TempFolder.Path? –dmb Apr 17 '10 at 22:18 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote Try adding the On Error Resu
United States Australia United Kingdom Japan Newsletters Forums Resource Library Tech Pro Free Trial Membership Membership My Profile People http://www.techrepublic.com/forums/discussions/vbs-error-handling-and-loops/ 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 error handling 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 Activity FAQs Guidelines Question 0 Votes Locked VBS Error Handling and Loops By alxcsby ยท 6 years ago I'm trying to objfso.copyfile error handling 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 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