Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Search for Folder Existence

Keywords:  Search for Folder Existence dirExist Directory Exist

Question:

How would I go about using the Search Extender to test for the existence of a folder or subfolder by name on all drive volumes?

Answer:

If you want to search for a directory you would not specify an unusual file mask.....You could do something like this...

If AddExtender("WSRCH34I.DLL") == @FALSE Then Message("Error", "There's a problem with WSRCH34I.DLL.")
dirname="windows"  ;dirname to find!!!!!!
drives = DiskScan(2)  ;get all local drives
drvnum = ItemCount(drives,@tab)   ;How many local drives are there?
BoxOpen("Directory searcher","")
For d = 1 To drvnum                     
    drv = ItemExtract(d, drives, @tab) ;extract each drive volume on at a time
    drvroot = StrCat(drv,"\");Gimme the root
    ;xxx.yyy is a file that doesn't exist, to speed up search
    handle=srchInit(drvroot, "xxx.yyy", "", 0, 48);Need a handle
    BoxTitle("Searching %drvroot% for %Dirname%")
    
    While @TRUE
      hit = srchNext(handle) ;Let's go searching
      if hit == ""  then break  ;We're outtahere if we come up empty-handed
      BoxText("filename :%hit%")
      lastslash=StrSub(hit,strlen(hit),1)
      if lastslash=="\";Dir found
         tempslash=StrIndexNC(hit,"\",strlen(hit)-1,@BACKSCAN)
         founddir=StrSub(hit,tempslash+1,strlen(hit)-tempslash-1)
         BoxText("Dirname :%hit%")
         if StrICmp(strlower(founddir),strlower(dirname))==0 
            Message("Directory Found", hit)
            goto Cancel
         endif
      EndIf
    EndWhile
    srchfree(handle)
Next

:Cancel
exit



Article ID:   W14613
Filename:   Search for Folder Existence.txt