Hello,
In the scriptcenter of MS I found a little script to remove all files
from a folder. It works perfect except when there a files in that
folder that are in use. In that case the script crashes with a
RT-error: Access denied - code 800A0046.
The directory I need it for must be cleaned up everyday but there are
always files of the current day in use.
Could someone help me to modify the current script so it will cleanup
all files except the one's in use.
The current script is:

Const DeleteReadOnly = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("F:\webMethods\IntegrationServer4\logs\*.*"),
DeleteReadOnly

Thanks
Frank



--
FVG
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Re: Delete files in a folder by JTW

JTW
Thu Apr 06 19:16:27 CDT 2006

In some instances, you can use the optional Force parameter in the
DeleteFile method (syntax: FileSpec, [Force]). In other instances,
this might not work and still throw the error.

You can also try adding the On Error Resume Next prior to your command,
but that will only continue the script when the DeleteFile method
errors out, and not complete the deletion past the point of error.

Lastly, you can change the process to first create an object of the
parent folder (objFldr = objFSO.GetFolder([path]), and then create a
collection of the files (set colFiles = objFldr.Files), then delete
each file using a loop (For Each objFile in colFiles : objFile.Delete
True), again using the On Error Resume Next prior to the loop.