Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Vbscript fso copy file not returning an error code

Posted on 2008-09-29
8
Medium Priority
?
7,082 Views
Last Modified: 2008-10-03
I have the following snipit of cod ethat copy a file.

However, when the copy fails I do not get an error return? Shouldn't this code snippit see an error?
I am setting "on error resume next, so it should continue when there is an error


Err.Clear
fso.CopyFile file, destPath,True            
If Err.Number <> 0 Then
processExitError "attemp to copy file failed " &  Chr(34) & file  & Chr(34) & "failed with error code " & Err.Description & "," & Err.Number
WScript.Quit(-1)                        
End If
Function copyFileButStripLeadingNumberFromSource(file, destPath)
	On Error Resume next
		If Len(file.name) > 3 Then
			header = Left(file.name, 2)			
			If IsNumeric(header) And Left(file.name, 3) = (header&"-") Then
				nameWIthPreceedingNumberRemoved = Right(file.name, Len(file.name) - 3)
				'search backwards for the first directory marker in the path 
				index = InStrRev(destpath, "\")
				If index = 0 Then			'no directory marker
					destpath = Replace(destpath, nameWIthPreceedingNumberRemoved)
				Else
					destpath = Left(destpath, index)
					destpath = destpath & nameWIthPreceedingNumberRemoved 
				End If
			End If
		End If
		copyFileButStripLeadingNumberFromSource= destPath
	    EchoAndLog "copy " &  file & " to " &  destPath
	    Err.Clear
		fso.CopyFile file, destPath,True		
		EchoAndLog "returnCode = " & Err.Description
		If Err.Number <> 0 Then
			processExitError "attemp to copy file failed " &  Chr(34) & file  & Chr(34) & "failed with error code " & Err.Description & "," & Err.Number 
			WScript.Quit(-1)				
		End If
		
End Function

Open in new window

0
Comment
Question by:Christopher Schene
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:zoofan
ID: 22602217
Where/what is the code for this function?  "processExitError"


zf
0
 
LVL 12

Expert Comment

by:zoofan
ID: 22602222
Or simply bypass that function with




zf
               If Err.Number <> 0 Then
                        'processExitError "attemp to copy file failed " &  Chr(34) & file  & Chr(34) & "failed with error code " & Err.Description & "," & Err.Number 
                         MsgBox Err.Number & " " & Err.Description & " " & Err.Source
                         WScript.Quit(-1)                                
                End If

Open in new window

0
 

Author Comment

by:Christopher Schene
ID: 22602307
That is not my problem, my problem is the the "err" object is not returning an error even when I know the copy has failed.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
lodar123 earned 1000 total points
ID: 22605493
well i tried a quick run at it and when i get an error (for example the file do not exist, i get the err description.
your copyfile statement needs to be in brackets...... remove your on error resume next and it will give you a syntax error

This works....
On Error Resume Next
fso.CopyFile(file1, destination,True)
MsgBox Err.description 
 
This gives a Syntax error...
fso.CopyFile file1, destination, True   <---- no bracket = not good
MsgBox Err.description 

Open in new window

0
 
LVL 5

Expert Comment

by:lodar123
ID: 22614704
Did you get it to work properly?
0
 

Author Comment

by:Christopher Schene
ID: 22623569
I think my problem may be that when in notepad, I don't get an error when I copy over the file.

let me try making the file read only and see whether that causes an error.
0
 
LVL 5

Expert Comment

by:lodar123
ID: 22623630
just make sure when you call fso.CopyFile(file1, destination,True) it as the brackets...or you get an syntax error... having on error resume next then this will be skipped and never get a return code
0
 

Author Comment

by:Christopher Schene
ID: 22635373
works....my real problem was that I thought that opening a file with note pad would prevent it from being overwritten. Instead I write protected the file and and the error was detected.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question