Page 1 of 1

How to .. recursive Dir Search

Posted: Sun Jan 11, 2015 4:30 pm
by Redlion
Hi all,

I am trying to do a directory search including subdirectories, but I can not get it to work.
I want to list all the Files and Directories that have the search test in there names
Here is the Function that I call.

Code: Select all


Function p_SearchDir(SearchDir$)

sd = OpenDirectory(NIL,SearchDir$)
Entry = NextDirectoryEntry(sd)
While Entry <> 0
  If Entry.type = #DOSTYPE_FILE
   If FindStr(Entry.name,SearchString$,False) > -1
      mui.DoMethod("ListSearch","Insert","Bottom",Entry.name)
    Endif 
  Endif
  If Entry.type = # DOSTYPE_DIRECTORY
     NSearchDir$ = SearchDir$..Entry.name
     p_SearchDir(NSearchDir$)
     mui.DoMethod("ListSearch","Insert","Bottom",Entry.name)
  Endif
  Entry = NextDirectoryEntry(sd)
Wend
CloseDirectory(sd)

EndFunction
Could anybody tell me what I have to do to get this to work.

I get an Error Requested object not found.

Thanks

Re: How to .. recursive Dir Search

Posted: Mon Jan 12, 2015 2:36 pm
by Redlion
Hi guys,

I figured it out, see below.

Code: Select all

@VERSION 5,2
@REQUIRE "MUIRoyale"
@APPTITLE "Dir Look"
@APPVERSION "$VER: Dir Look 1.0 (01.01.15)"
@APPCOPYRIGHT "©2015, George Leo den Hollander"
@APPAUTHOR "Leo den Hollander"
@APPDESCRIPTION "Directory Program"

@DISPLAY {Hidden = True}

mui.CreateGui([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application base="TEST">
<window title="DIR LOOK - Directory Search Program" id="window" notify="closerequest" >
  <vgroup background="pre_ShadowFill">
    <hgroup>
      <vgroup>
        <listview id="lv1_directory" notify="Active; Doubleclick"  multiselect="default" fixheight="260" fixwidth="260">
          <column/>
        </listview>
        <string id="lv1" contents="DH0:"/>
      </vgroup>
      <vgroup  weight="50">
        <vgroup>
          <button id ="Find"   notify="pressed" fixwidth="100">\33b Find File  </button>
          <rectangle/>
        </vgroup>
        <vgroup>
        <button id ="quit"   notify="pressed" fixwidth="100">\33b Quit   </button>
        </vgroup>
      </vgroup>
    </hgroup>
  </vgroup>
</window>
</application>
]])

function p_search(SearchDir$) ; * Search Drive **********************************************************************************
local dirno
local Lookdir$
LookDir$ =  SearchDir$
dirno = OpenDirectory(NIL, LookDir$)
local Entry
Entry = NextDirectoryEntry(dirno)
  While Entry <> Nil
    If Entry.type = #DOSTYPE_FILE
      if FindStr(Entry.name, Search$, False) > -1
        mui.DoMethod("lv1_directory", "Insert", "Bottom", Entry.name)
        SN = SN + 1
        mui.Set("lv1", "contents", SN.." Files Found")
      EndIf
    EndIf
    If Entry.type = #DOSTYPE_DIRECTORY
       LookDir$ = LookDir$..Entry.name.."/"
        p_search(Lookdir$)
        LookDir$ = SearchDir$
     EndIf
    Entry = NextDirectoryEntry(dirno)
  Wend
  CloseDirectory(dirno)
endfunction

Function p_MUIEvent(id) ; * Joint event handler for MUI buttons and menus *************************************************
  Switch id
    Case "Find"
      SearchFrom$ = mui.Get("lv1","Contents")
      Search$,ok = StringRequest("Searching for file :","Searching "..SearchFrom$.."\n\nPlease enter File Name. ","")
      if ok
        p_search(SearchFrom$)
        mui.Set("lv1","contents",SN.." Files Found - Finished")
      endif
    Case "quit":
      End
  EndSwitch
EndFunction

Function p_EventFunc(msg)
  Switch msg.action
    Case "MUIRoyale":
      Switch msg.attribute
        Case "CloseRequest":
          End
        Case "Pressed":
          p_MUIEvent(msg.id)
       endswitch
    Case "HideWindow":
        mui.Set("app", "iconified", True)
    Case "ShowWindow":
        mui.Set("app", "iconified", False)
  EndSwitch
EndFunction

; listen to these events!
InstallEventHandler({MUIRoyale = p_EventFunc, HideWindow = p_EventFunc, ShowWindow = p_EventFunc})

; main loop!
Repeat
     WaitEvent
Forever