Hello!
I updated the code for the 4th time. Please, have a look at the 4th code in this thread. It now supports callbacks.
[Old Post]
Hello!
// Edit: my second code below finds more than just the first file.
I just created a code that I wanted to post into the german forum.
This code searches for the first file matching the given parameter:
Code: Select all
; AND51
; Nov-2007
; For free use, credits appreciated
Procedure.s FindFile(file.s, directory.s, recursive=1)
PathAddBackslash_(@directory)
Protected result.s, dir=ExamineDirectory(#PB_Any, directory, file)
If dir And NextDirectoryEntry(dir)
result=directory+DirectoryEntryName(dir)
FinishDirectory(dir)
ElseIf recursive
dir=ExamineDirectory(#PB_Any, directory, "")
If dir
While NextDirectoryEntry(dir) And Not result
If DirectoryEntryType(dir) = #PB_DirectoryEntry_Directory And DirectoryEntryName(dir) <> "." And DirectoryEntryName(dir) <> ".."
result=FindFile(file, directory+DirectoryEntryName(dir), 1)
EndIf
Wend
FinishDirectory(dir)
EndIf
EndIf
ProcedureReturn result
EndProcedure
Debug FindFile("hiberfil.sys", "C:", 1)
- Case-In-Sensivity
- Recursive search is optional
- Wildcards can be used
- Intelligent search algorithm: Before entering any sub-directory, the current directory is being examined for the file. Normal codes instantly enter a subdirectory if it comes alphabetically before the filename
Edit:
Improved the pattern at ExamineDirectory(), should now work.
I removed the star (wildcard), otherweise he could fint "purebasic.exe", although you want to search for "basic.exe").