Wilson WindowWare Tech Support

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


Recursive directory name search

Keywords:  Dir name wildcard DirExist recurse

Question:

I am trying to find all directories with the string 'net' in them. The function DirExist doesn't accept wildcards..... Do you have any suggestions,

Answer:

You will nee to use the File Searcher Extender, for this type of job.

Something like this....

If AddExtender("WSRCH34I.DLL") == @FALSE Then Message("Error", "There's a problem with WSRCH34I.DLL.")
dirname="*net*"  ;wildcarded 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
    handle=srchInit(drvroot, "", "", 0, 48);Need a handle
    BoxTitle("Searching %drvroot% for %Dirname%")
    While 1
            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%")
               ;Finds wildcarded text within a larger string..
               if StrIndexWild(founddir, dirname, 1)
                        Message("Directory Found", hit)
               endif
            EndIf
    EndWhile
    srchfree(handle)
Next


:Cancel

exit


Article ID:   W14611
Filename:   Recursive directory name search.txt