PDA

View Full Version : script error (W2K)



Nov14u
12-18-2002, 08:33 AM
I made very simple start up script to delete a folder

// JScript.
var FSO = WScript.CreateObject("Scripting.FileSystemObject");
FSO.deleteFolder("c:\\documents and settings\\pac*");

The problem I am having is that if the file is not there it gives the user an error message when they login . How can I correct this. This is the first time i experimented with it so any advice is greatly appreciated

Andy-S
12-18-2002, 09:00 AM
As you are only doing the one action a simple solution would be to add On Error Resume Next e.g.

On Error Resume Next
var FSO = WScript.CreateObject("Scripting.FileSystemObject");
FSO.deleteFolder("c:\\documents and settings\\pac*");


Cheers
Andy

adamdelves
12-18-2002, 10:38 AM
I think that only works with VB Script in J Script you'd use try...catch.
<pre>
var FSO = WScript.CreateObject("Scripting.FileSystemObject");

try
{
// catch any errors in this scope
FSO.deleteFolder("c:\\documents and settings\\pac*");
}

catch
{
// when an error occurs code here will be executed
// do nothing becuse script runs at startup
}
</pre>

Andy-S
12-18-2002, 11:08 AM
adamelves,

You're right.

Nov14u, sorry for any confusion. I just assumed it was VBS without even looking at the code.

Cheers
Andy