On Error Resume Next

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

On Error Resume Next

Post by BlackWisdom » Tue Jul 12, 2005 2:36 am

Hey guys I’m modifying a script to Count folders on each drive of a system.
the script works fine - but if it tries to Count folders on a drive that does not
exist it generates a path not found error . I tried using on Error Resume Next
- but I dont think Macro Scheduler recognizes it. Here is the script :


VBSTART

Function NumFolders(Path)

set objFS = CreateObject("Scripting.FileSystemObject")

set objFolder = objFS.GetFolder(path)

NumFolders = objFolder.SubFolders.Count

End Function

VBEND

VBEval>NumFolders("c:\"),NumFldrs
WLN>Count.txt,%NumFldrs%

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Jul 12, 2005 8:26 am

On Error Resume Next works just fine. No errors when using a made up drive letter in the function call:

VBSTART

Function NumFolders(Path)
On Error Resume Next

set objFS = CreateObject("Scripting.FileSystemObject")
set objFolder = objFS.GetFolder(path)
NumFolders = objFolder.SubFolders.Count
End Function

VBEND

VBEval>NumFolders("x:\"),NumFldrs
WLN>Count.txt,result,%NumFldrs%
Last edited by support on Tue Jul 12, 2005 5:42 pm, edited 1 time in total.
MJT Net Support
[email protected]

BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

interesting.. but it works

Post by BlackWisdom » Tue Jul 12, 2005 4:19 pm

I pasted your reply into Macro Scheduler - when you run it you get the following value returned instead of the folder count - %NumFldrs%

However if you compile it and run the exe the correct number value for folders is returned.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Jul 12, 2005 5:41 pm

The last line is wrong. It should be:

WLN>Count.txt,result,%NumFldrs%

I fail to see why results would differ between compiled version and version run natively.
MJT Net Support
[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts