Page 1 of 1

FindFile ()

Posted: Thu Feb 03, 2005 9:35 am
by dige
Code updated for 5.20+

Code: Select all

; Find a file recursively : by DiGe 03/Feb/2005

Procedure FindFile ( Directory.s, File.s )
  DirNr = ExamineDirectory(#PB_Any, Directory, "*.*" )
  If DirNr
    While NextDirectoryEntry(DirNr)
      If DirectoryEntryType(DirNr) = #PB_DirectoryEntry_File
        If UCase(File) = UCase(DirectoryEntryName(DirNr))
          Debug "Found at : " + Directory
        EndIf
      ElseIf DirectoryEntryType(DirNr) = #PB_DirectoryEntry_Directory And DirectoryEntryName(DirNr) <> ".." And DirectoryEntryName(DirNr) <> "."
        FindFile(Directory + "\" + DirectoryEntryName(DirNr), File.s)
      EndIf
    Wend
    
    FinishDirectory(DirNr)
  EndIf
EndProcedure

; Example, run with debugger enabled
FindFile( "C:\Windows", "EXPLORER.exe" )

Posted: Thu Feb 03, 2005 2:56 pm
by GPI
Verbesserungsvorschlag: Wenn man nach "EXPLORER.EXE" sucht, findet man kein "explorer.exe".

Posted: Thu Feb 03, 2005 3:05 pm
by gnozal
Translation :wink:

Code: Select all

Improvement suggestion : if you search for 'EXPLORER.EXE', you don't find 'explorer.exe'

Posted: Thu Feb 03, 2005 4:33 pm
by GPI
ups. i thougt, that i'm in the german forum...

Posted: Thu Feb 03, 2005 5:13 pm
by Tommeh
GPI, I wouldnt have thought it would be much trouble for you.... lol

Here is the code altered to allow case sensitivity, not much really needed.. Good work Dige :-)

Code: Select all


Procedure FindFile ( Directory.s, File.s, CaseS )
  DirNr = ExamineDirectory( #PB_Any, Directory, "*.*" )
  If DirNr
    Repeat
      Result = NextDirectoryEntry()
      If Result = 1
        
        DirEntryName$ = DirectoryEntryName()
        
        If CaseS = 0
        File = LCase(File)
        DirEntryName$ = LCase(DirEntryName$)
        EndIf
        
        If File = DirEntryName$
          Debug "Found at : " + Directory
                    
        EndIf
      ElseIf Result = 2 And DirectoryEntryName() <> ".." And DirectoryEntryName() <> "."
        FindFile ( Directory + "\" + DirectoryEntryName() , File.s , CaseS )

        UseDirectory(DirNr)
      EndIf
    Until Result = 0
  EndIf
EndProcedure

; Example, run with debugger enabled
FindFile( "C:\Windows", "EXPLORER.exe" , 0 )


Posted: Thu Feb 03, 2005 6:54 pm
by blueznl
viewtopic.php?t=8359&highlight=xdir

not recursively though...