Add basic error handling to vsbscript

I have some vbs script that converts filenames from a hex number to a decimal in a local folder c:\jpg. I am trying to run this script on on about 10gb of 20-30k images but it has now stopped with the error message"
ERROR:FILE ALREADY EXISTS
CODE: 800A003A
SOURCE: Microsoft VBScript runtime error
it has processed some of the files and if i start it again i get the same error message.

I am after some code that will skip the problem filename and carry on. logginf that filename to an error log would be good also.

Cananyone help 500 points for this as its v-urgent.

My script loooks like this

Dim fso, folder, oRe, oMatch, oMatches, i , j, d, s

folder="e:\jpg" 'folder to process
'folder=WScript.Arguments(0) 'uncomment this line to pass the folder name as command line argument

Set re = New RegExp
re.Pattern = "^([0-9A-Z]{8})\.JPG$"
re.IgnoreCase = True  

Set fso = createobject("scripting.filesystemobject")
For each f in fso.getfolder(folder).Files
  If re.Test(f.Name) Then 'file as a name like HHHHHHHH.JPG    
    i=CLng("&h" & Left(f.name,8)) 'convert to decimal
    If i>=0 and i<=999999999 Then
      d=CStr(i) 'convert to string
      d=String(9-Len(d),"0") & d 'pad with 0
      'calc check digit
      s=0
      For j=1 to 9
        s=s+(11-j)*CInt(Mid(d,j,1))
      Next
      s=(11-(s mod 11)) mod 11
      If s=10 Then
           d=d & "X"
      Else
        d=d & CStr(s)
      End If
      d = d & ".JPG"
'      wscript.echo "renaming " & f.name & " to " & d
      f.move fso.BuildPath(f.parentfolder.path, d)
    End If    
  End If  
Next
boldnbrash73Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

boldnbrash73Author Commented:
I wasnt sure which area to post in as XP comes with the scripting host without the need for VB so could may be  covered in the  Windows XP section, but then again VBS is another flavour of Visual Basic so its going to fit in there too.  I''ve had no luck here yet so If you think ill get a better response then yes, please do move it.

thanks
Mark
0
AzraSoundCommented:
At the top of your script, add the following line of code:

On Error Resume Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AzraSoundCommented:
As for logging, you could do something like this:


On Error Resume Next

Dim fso, folder, oRe, oMatch, oMatches, i , j, d, s
Dim errLog    '***** error log


folder="e:\jpg" 'folder to process
'folder=WScript.Arguments(0) 'uncomment this line to pass the folder name as command line argument

Set re = New RegExp
re.Pattern = "^([0-9A-Z]{8})\.JPG$"
re.IgnoreCase = True  

Set fso = createobject("scripting.filesystemobject")
Set errLog = fso.OpenTextFile("C:\myerrors.txt", 2, True)

For each f in fso.getfolder(folder).Files
  If re.Test(f.Name) Then 'file as a name like HHHHHHHH.JPG    
    i=CLng("&h" & Left(f.name,8)) 'convert to decimal
    If i>=0 and i<=999999999 Then
      d=CStr(i) 'convert to string
      d=String(9-Len(d),"0") & d 'pad with 0
      'calc check digit
      s=0
      For j=1 to 9
        s=s+(11-j)*CInt(Mid(d,j,1))
      Next
      s=(11-(s mod 11)) mod 11
      If s=10 Then
           d=d & "X"
      Else
        d=d & CStr(s)
      End If
      d = d & ".JPG"
'      wscript.echo "renaming " & f.name & " to " & d
      f.move fso.BuildPath(f.parentfolder.path, d)

      If Err.Number <> 0 Then
          'error occurred - log it
          errLog.WriteLine "Error renaming " & f.name & " to " & d
          Err.Clear
      End If

    End If    
  End If  
Next

         
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.