Author Topic: deleting all .nsf files  (Read 1682 times)

stevent

  • Newbie
  • *
  • Posts: 1
deleting all .nsf files
« 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

stanl

  • Pundit
  • *****
  • Posts: 612
Re: deleting all .nsf files
« Reply #1 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.

td

  • Tech Support
  • *****
  • Posts: 2057
    • WinBatch
Re: deleting all .nsf files
« Reply #2 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'.



"DON'T PANIC”
The Hitchhiker's Guide to the Galaxy, Douglas Adams