![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | err object and looping I have a script that reads folders for files, and then opens them and e-mails them if they exist. I have some trouble where if the file is still being created when I discover it, the script fails. I've used err.number for other things, but I'm not sure if this will work: can you loop around an err.number? like this: fName = LCase(f1.name) writelog("Opening File: "&fname) ' Writelog is a separate function Set f2 = fso.opentextfile(folderspec3&"\"&fname) Do While err.number <> 0 Writelog ("Error: " & err.description & "Encountered, Waiting 30 Seconds") wscript.sleep 30000 Set f2 = nothing err.clear Set f2 = fso.opentextfile(folderspec3&"\"&fname) Loop |
My System Specs![]() |
| | #2 (permalink) |
| | Re: err object and looping "Lee" <ldspmAT@xxxxxx> wrote in message news:AA60D3FC-CD7C-408D-86B0-F735BB9F078A@xxxxxx Quote: >I have a script that reads folders for files, and then opens them and >e-mails them if they exist. > > I have some trouble where if the file is still being created when I > discover it, the script fails. > > I've used err.number for other things, but I'm not sure if this will work: > can you loop around an err.number? > like this: > > fName = LCase(f1.name) > writelog("Opening File: "&fname) ' Writelog is a separate > function > Set f2 = fso.opentextfile(folderspec3&"\"&fname) > Do While err.number <> 0 > Writelog ("Error: " & err.description & "Encountered, Waiting > 30 Seconds") > wscript.sleep 30000 > Set f2 = nothing > err.clear > Set f2 = fso.opentextfile(folderspec3&"\"&fname) > Loop error resume next". You should also remove the statement "Set f2 = nothing" - it only generates additional errors which can confuse the issue. If you wish to test for the existence of your file then the oFSO.FileExists method would be a more elegant solution. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: err object and looping On Feb 25, 11:05*am, "Lee" <ldsp...@xxxxxx> wrote: Quote: > I have a script that reads folders for files, and then opens them and > e-mails them if they exist. > > I have some trouble where if the file is still being created when I discover > it, the script fails. > > I've used err.number for other things, but I'm not sure if this will work: > can you loop around an err.number? > like this: > > * * * * * fName = LCase(f1.name) > * * * * * writelog("Opening File: "&fname) *' Writelog is a separate > function > * * * * * Set f2 = fso.opentextfile(folderspec3&"\"&fname) > * * * * * Do While err.number <> 0 > * * * * * * *Writelog ("Error: " & err.description & "Encountered, Waiting > 30 Seconds") > * * * * * * *wscript.sleep 30000 > * * * * * * *Set f2 = nothing > * * * * * * *err.clear > * * * * * * *Set f2 = fso.opentextfile(folderspec3&"\"&fname) > * * * * * Loop with an On Error Resume Next statement, maybe something like this ... On Error Resume Next ' take control of error trapping Do err.clear Set f2 = fso.opentextfile(folderspec3&"\"&fname) if err.Number <> 0 then Writelog ("Error: " & err.description _ & "Encountered, Waiting 30 Seconds") wscript.sleep 30000 Set f2 = nothing else exit do end if Loop On Error Goto 0 ' return control to the host Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
| | #4 (permalink) |
| | Re: err object and looping "T Lavedas" <tglbatch@xxxxxx> wrote in message news:675d9b87-5bfd-4261-a51b-6b4071422beb@xxxxxx On Feb 25, 11:05 am, "Lee" <ldsp...@xxxxxx> wrote: Quote: > I have a script that reads folders for files, and then opens them and > e-mails them if they exist. > > I have some trouble where if the file is still being created when I > discover > it, the script fails. > > I've used err.number for other things, but I'm not sure if this will work: > can you loop around an err.number? > like this: > > fName = LCase(f1.name) > writelog("Opening File: "&fname) ' Writelog is a separate > function > Set f2 = fso.opentextfile(folderspec3&"\"&fname) > Do While err.number <> 0 > Writelog ("Error: " & err.description & "Encountered, Waiting > 30 Seconds") > wscript.sleep 30000 > Set f2 = nothing > err.clear > Set f2 = fso.opentextfile(folderspec3&"\"&fname) > Loop with an On Error Resume Next statement, maybe something like this ... On Error Resume Next ' take control of error trapping Do err.clear Set f2 = fso.opentextfile(folderspec3&"\"&fname) if err.Number <> 0 then Writelog ("Error: " & err.description _ & "Encountered, Waiting 30 Seconds") wscript.sleep 30000 Set f2 = nothing else exit do end if Loop On Error Goto 0 ' return control to the host Tom Lavedas *********** ============= You might want to consider other reasons for such a failure, as these might not all resolve themselves. If, for example, the folderspec3 refers to a mapped folder that is no longer mapped... or if you have only read access... /Al |
My System Specs![]() |
| | #5 (permalink) |
| | Re: err object and looping it's a local file on the C:\ Drive. I do an err.clear before this part of the script, and I have on error resume next already in place. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Looping through directory | VB Script | |||
| Why is my foreach loop only looping through the first object in th | PowerShell | |||
| Looping and If Structures | Vista General | |||
| AD Changes and Looping | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||