WinBatch® Technical Support Forum

Archived Boards => WinBatch Script Exchange => Topic started by: stevent on April 19, 2016, 09:40:46 AM

Title: deleting all .nsf files
Post by: stevent on April 19, 2016, 09:40:46 AM
Hello -
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?
Ex.;
AddExtender("wsrch34i.dll")
drives=DiskScan(2)
drvnum=ItemCount(drives,@TAB)
bakcount=0
baksize=0
For d=1 To drvnum
   drv=ItemExtract(d,drives,@TAB)
   ;BoxOpen("Checking %drv% drive","")
   drvroot=StrCat(drv,"\")
   handle=SrchInit(drvroot,"*.nsf","","",16)
   While 1
      bakfile=SrchNext(handle)
      If bakfile=="" Then Break
      bakcount=bakcount+1
      baksize=baksize+FileSize(bakfile)
      ;BoxText("%bakfile% deleted")
      FileDelete(bakfile)
   EndWhile
   SrchFree(handle)
Next
Exit
Title: Re: deleting all .nsf files
Post by: stanl on April 19, 2016, 10:42:56 AM
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.
Title: Re: deleting all .nsf files
Post by: td on April 19, 2016, 10:45:08 AM
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'.