Multiple file extensions in ExamineDirectory() ?

Just starting out? Need help? Post your questions and find answers here.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: Multiple file extensions in ExamineDirectory() ?

Post by TerryHough »

Vera wrote:Could you have a look if you experience something similar like: 3 found files / total Count 190 files - while there are only 20 files inside the folder (w/o sub) and the summed up found files is also far below this amount.
I ran your code here on my test directory several times. It returned an accurate count each time. Crosschecked the count with my 3 different routines. All agreed with your count.

So, sorry, I wasn't able to duplicate your failure.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Multiple file extensions in ExamineDirectory() ?

Post by Vera »

Oh well - thanks for looking.
But as I said - I can't make out what the range of the result shall be, so I would like to ask to be able to compare the results with the given reality to hunt the reason for the deviations.

There are 3 MessageRequesters
What does Str(Count) (in the first and second msr) really count - what is the result supposed to tell me ?
All processed files of the current directory in/excluding subfolders ? Or maybe all files that were no hits ? Or is it accumulating / regarding previous results or depending on jumping from one tree to the next?

And the same with Str(Files) from the final MessageRequester.
Which files are meant ? (hits / no hits / all processed / only the last finds of the last processed dir or the whole last tree ...?)
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: Multiple file extensions in ExamineDirectory() ?

Post by TerryHough »

@vera

The procedure "count"s the files that match the pattern. Then it returns "count" as the final result of the procedure.

"Files" receives the results of the procedure (count).
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Multiple file extensions in ExamineDirectory() ?

Post by Vera »

@TerryHough
sorry I get no answer - that these results are returned from the procedure is obvious but it doesn't itemize what is meant by them.

@All
please beware the returned 'Count' results as for me they are always wrong, even may differ between the two outcomes of both messagerequesters. The final result is always wrong [inexplicable].
Still it's a valuable procedure as the returned matches (and listings) themselfs haven't failed. 8)
Testet both on WIN and LINUX, likewise with the original code and the extended one.

Example of what I'm talking about:
--------------
CountGadgetItems(0) = 3 <- true
Str(Count) = 12 <- wrong [indissoluble value]
real: 35 files / no subfolders / 3 matches
--------------
CountGadgetItems(0) = 5 <- true
Str(Count) = 17 <- wrong [indissoluble value]
real: 5 files / no subfolders / 5 matches
--------------
Final messagerequester:
Str(Files) = 27 <- wrong [indissoluble value]

real: 34 objects: 12 folders, 22 files
-> 6 files are matching in this last/root directory
-> 53 files are matching including all subdirs
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: Multiple file extensions in ExamineDirectory() ?

Post by TerryHough »

@vera
Try this revised version. I snipped the original code and missed a variable definition. "Count" must be a static or global variable.

Code: Select all

Global Msg$ 

Procedure RecursivelyExploreDirectory(SourceDirectory$, Start, Pattern$)
  Static Count  ; must be a static or global variable
  If ExamineDirectory(Start, SourceDirectory$, "*.*")
    While NextDirectoryEntry(Start)
      Select DirectoryEntryType(Start)
        Case #PB_DirectoryEntry_Directory
          If DirectoryEntryName(Start) <> "." And DirectoryEntryName(Start) <> ".."
            a$ = SourceDirectory$+DirectoryEntryName(Start)+"\"
            Start+1
            RecursivelyExploreDirectory(a$, Start, Pattern$)
            ExplorerListGadget(0, 0, 0, 0, 0,  a$ + pattern$, #PB_Explorer_NoFolders | #PB_Explorer_NoParentFolder)
            Start-1
          EndIf
      EndSelect
    Wend
    FinishDirectory(Start)
    ExplorerListGadget(0, 0, 0, 0, 0,  SourceDirectory$ + Pattern$, #PB_Explorer_NoFolders | #PB_Explorer_NoParentFolder)
   ;Do whatever you need to with the contents resulting explorer file list
    If CountGadgetItems(0) > 0
      Count + CountGadgetItems(0) ; increase selected file count
      ; Optionally, report folder results in a message
      Msg$ + SourceDirectory$ + ": " + Str(CountGadgetItems(0)) + " in folder" + " - " + Str(count) + " total files" + #LF$
      ; Optionally, add each selected file to external list
      For K = 0 To CountGadgetItems(0)-1  
        AddGadgetItem(2,-1,SourceDirectory$ + GetGadgetItemText(0,k,0))
      Next  
    EndIf   
  EndIf
  ProcedureReturn Count
EndProcedure

SetCurrentDirectory("C:\folder\")

If OpenWindow(0, 0, 0, 400, 200, "Recursive Explorer List", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListViewGadget(2,10,10,380,180) ; results list if desired
  Starttime = ElapsedMilliseconds() ; timer start
  Files.l = RecursivelyExploreDirectory(GetCurrentDirectory(),1,"*.exe;*.dll")
  Totaltime = ElapsedMilliseconds() - Starttime  ; capture operation time
  ; Optionally, build a report message
  Msg$ + #LF$ + Str(Files) + " files selected from target folder" + #LF$ 
  Msg$ + Str(CountGadgetItems(2)) + " listed" + #LF$ 
  Msg$ + Str(Totaltime) + " ms"
   MessageRequester("Find Files", Msg$ , #MB_ICONINFORMATION) 
  ; end optional report message
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End 
Post Reply