[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Delete files in a dirusing Windows Script

Hello,
In the scriptcenter of MS I found a little script to remove all files from a dir. It works perfect except when there are files in that dir that are in use. in that case the script crashes with a RT-error: Access Denied - code 800A0046.
The dir where I need the script for, must be cleaned up every day but there are always files in use. Could soneone help me to modify the script so that ik will cleanup all files except those who are in use.

This is the script I've used:
Const DeleteReadOnly = TRUE
Set objFSO = CreateObject("Scripting.FilesSystemObject")
objFSO.DeleteFile("F:\WebMethods\IntegrationServer4\logs\*.*"),
DeleteReadOnly

Thanks
Frank
0
fvg
Asked:
fvg
  • 3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if files are in use, you cannot deleted them.
the only think you can do is mark them for deletion in the registry so they get deleted on the next reboot.

If the application only releases the lock on the file when restarting, you have to restart the application
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
to workaround:

Const DeleteReadOnly = TRUE
Set objFSO = CreateObject("Scripting.FilesSystemObject")

set folder = objFSO.Getfolder("F:\WebMethods\IntegrationServer4\logs\")
on error resume next
for each file in folder.files
  file.delete
  err.clear
next
0
 
fvgAuthor Commented:
To angelIII
Maybe I have explained myself in a wrong way but what I need is a script that deleted the files that are NOT in use. The files in use may stay in the dir.
The script I used will not delete all the files NOT in use because it crashes as soon as it detects a file that is in use.
Regards
Frank
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
well, with the error handler (on error resume next) the script should not crash but continue...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now