Objfso.movefile Error Handling
Contents |
for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search
Vbscript Copyfile Error Handling
Submit Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services Groups Website vbs copyfile Testing Store Headlines Experts Exchange > Questions > MoveFile/CopyFile in VBS and error handling Want to Advertise Here? Solved MoveFile/CopyFile in VBS vbscript error handling and error handling Posted on 2004-05-03 Visual Basic Classic 2 Verified Solutions 10 Comments 5,272 Views Last Modified: 2012-06-27 The MoveFile and CopyFile methods in VBS does not return a code specifiying if there was an error or not performing the call. What's the best way to know if a file was moved or copied? Doing a FileExists doesn't seem to guarantee that the file was copied completely. The files being copied are on a local PC and the destination is to an FTP server using WebDrive. Thanks. 0 Question by:halfondj Facebook Twitter LinkedIn Google LVL 28 Best Solution byvinnyd79 what about getting the filesize before the copy,then comparing it after: Dim GetFileSize1,GetFileSize2,objFSO,f,Fname1,Fname2 Set objFSO = WScript.CreateObject("Scripting.FileSystemObject") Fname1 Go to Solution 10 Comments LVL 53 Overall: Level 53 Visual Basic Classic 24 Message Expert Comment by:Dhaest2004-05-03 You can add the standard exception method to your program: private sub Start 'Begin of script On Error GoTo StandardErrorHandler ' All your functions, like movefile, ... exit sub StandardErrorHandler: msgbox "copy failed" end sub 0 LVL 4 Overall: Level 4 Visual Basic Classic 2 Message Expert Comment by:marper2004-05-03 try also If Len(Trim(Dir("yourpath\yourfile,vbNormal))> 0 Then 'File is there end if 0 Message Author Comment by:halfondj2004-05-03 I'm using VBS, not VB. It's my understanding that one can only use 'On Error Resume Next' in VBS. For a test, I've implemented the following code, but if I disconnected the mapped drive (the drive that was mapped via WebDrive) when the CopyFile was taking place, the CopyFile still returned successful, not unsuccessful. I need to ensure that the CopyFile/MoveFile returns unsuccessful, when in fact, the file did not copy fully to the destination folder. Here's the test code snippet: : Set objFSO = WScript.CreateObject("Scripting.FileSystemObject") on error resume next objFSO.CopyFile "x:\bigtestfile.txt", "q:\bigtestfile.txt" if err.number<>0 then set objFSO = Nothing wscript.echo err.description 'wscript.echo "Path not found. Operation aborted." wscript.quit(1) end if on e
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 https://www.experts-exchange.com/questions/20976243/MoveFile-CopyFile-in-VBS-and-error-handling.html 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) http://www.tek-tips.com/viewthread.cfm?qid=424854 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.
(עברית)المملكة العربية السعودية (العربية)ไทย (ไทย)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語) 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 https://social.technet.microsoft.com/Forums/scriptcenter/en-US/49eaa9f5-8af1-4a3d-8799-b8becf56b072/vbs-error-handling-with-a-do-until-loop?forum=ITCG 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 a separate file (C:\MassCopyError.txt) for each PC that fails, then notify me when it's error handling 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 objfso.movefile error handling 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.Clear
End If
wscipt.Echo "MassCopy has finished copying files."
Thursday, August 19, 2010 8:20 PM Reply | Quote Answers 1 Sign in to vote It would appear to me that you want to put the error logging inside the loop