WinBatch Technical Support Forum
All Things WinBatch => WinBatch Script Exchange => Topic started by: stevent on April 19, 2016, 09:40:46 am
I am trying to create a WB script that searches for and then deletes all files with an .nsf extension. Thus far my script has the unfortunate aspect of running, and running up to 28% CPU usage. My question for anyone out here is does anyone have a way to limit the search function to only search for local drives and delete things by a wildcard reference?
For d=1 To drvnum
;BoxOpen("Checking %drv% drive","")
If bakfile=="" Then Break
An alternative: Use WMI to delete the files. I think the CIM_Datafile object has a delete method. There may be a sample in the WB Tech Support.
You have to keep in mind that the average file system has many hundreds of thousands of files so any approach is going to take awhile. If you have a system with an indexed file system, the quickest approach would likely be to find some tool that takes advantage of the indexing.
Another possible alternative implementation in a WIL script that may be a little quicker than your current script would be to use the File and Folder Finder (hate that name) extender to traverse each drives directory structure. You could call the Shell Operations extender's aFileDelete function on each directory to delete any '.nsf' files in the directory. The thinking behind this strategy is that FaF extender is faster at traversing the directory structure than the Search extender and the aFileDelete function will perform the identification and deletion in native machine instructions which should be much faster than a WIL loop calling FileDelete on each file. You could also just use FileDelete on each directory with the '*.ndf' wild card. Not sure if it would be that much slower than aFileDelete.
Of course, there is always the command line shell's 'del /S *.nsf'.