How to detect result of FileSystemObject delete method

B

Brad Wood

The delete method of the FileSystemObject.FileObject does not return a
result. If permissions disallow deletion, it will not raise an error.
Conversely, if the delete method does succeed, a call to FileExists directly
afterward may return true because the system hasn't updated yet (or whatever
actually goes on).

Is there any way to accurately check the result of a deletion?
 
R

Ray at

Brad Wood said:
The delete method of the FileSystemObject.FileObject does not return a
result. If permissions disallow deletion, it will not raise an error.


This is not true! Where did you hear this?

Error: Permission denied
Code: 800A0046
Source: Microsoft VBScript runtime error


Ray at work
 
B

Brad Wood

Server 2003, using the FileSystemObject in JScript within a try catch block,
I call Delete on a file I don't have permissions to delete, and the code
just keeps on cruisin; the file still exists and the code within the catch
block never executes.

Maybe you get different results when using the FileSystemObject within
VBScript?
 
R

Ray at

Can you post your code?

Ray at work

Brad Wood said:
Server 2003, using the FileSystemObject in JScript within a try catch block,
I call Delete on a file I don't have permissions to delete, and the code
just keeps on cruisin; the file still exists and the code within the catch
block never executes.

Maybe you get different results when using the FileSystemObject within
VBScript?
 
B

Brad Wood

try
{
var fsoObject = Server.CreateObject("Scripting.FileSystemObject");
// array of paths - I verified they exist
// (the files are removed if the parent folder permissions are set to
allow it)
for (var i = 0; i < deleteFileArray.length; i++)
if (fsoObject.FileExists(deleteFileArray))
{
var fileObject = fsoObject.GetFile(deleteFileArray);
fileObject.Delete(true);
}
}
catch(e)
{
// Never see this text - file still exists after function call (when
permissions denied)
Response.Write('Error while attempting to delete file</br>');
Response.Write(e.description);
Response.End();
}

// remove a database record here - record is deleted and user is redirected
to another
// page as specified in calling code
 
R

Rob Greene

I'm on a W2K3 system. I tried (a modification of) your code and found that I'm throwing and catching errors. I could not see anything wrong
with your code, but my code is working as desired. Maybe there is someing you your array that's not acting correctly. I hope this helps.

My web page results:
File exist, let's delete it

Error while attempting to delete file
Permission denied

My code:

<%@language=jscript %>
<%
function DeleteIt( DeleteThis )
{
try
{
var fsoObject = Server.CreateObject("Scripting.FileSystemObject");
if ( fsoObject.FileExists( DeleteThis ))
{
Response.Write("File exist, let's delete it<br>" );
var fileObject = fsoObject.GetFile( DeleteThis );
fileObject.Delete(true);
}
Response.Write("File deleted" );
}
catch (e)
{
// Never see this text - file still exists after function call (when permissions denied)
Response.Write("<br>Error while attempting to delete file</br>");
Response.Write(e.description);
Response.End();
}
}

%>

<body>
<li></li>
<%
DeleteIt( "c:\\junk\\DeleteThis.txt")
%>
<li></li>
</body>



-rwg
This is what I think, not necessarily what is accurate!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top