Share your advanced PureBasic knowledge/code with the community.
-
dige
- Addict

- Posts: 1413
- Joined: Wed Apr 30, 2003 8:15 am
- Location: Germany
-
Contact:
Post
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" )
-
GPI
- PureBasic Expert

- Posts: 1394
- Joined: Fri Apr 25, 2003 6:41 pm
Post
by GPI »
Verbesserungsvorschlag: Wenn man nach "EXPLORER.EXE" sucht, findet man kein "explorer.exe".
-
gnozal
- PureBasic Expert

- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
-
Contact:
Post
by gnozal »
Translation
Code: Select all
Improvement suggestion : if you search for 'EXPLORER.EXE', you don't find 'explorer.exe'
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
GPI
- PureBasic Expert

- Posts: 1394
- Joined: Fri Apr 25, 2003 6:41 pm
Post
by GPI »
ups. i thougt, that i'm in the german forum...
-
Tommeh
- Enthusiast

- Posts: 149
- Joined: Sun Aug 29, 2004 2:25 pm
- Location: United Kingdom
Post
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 )
-
blueznl
- PureBasic Expert

- Posts: 6166
- Joined: Sat May 17, 2003 11:31 am
-
Contact:
Post
by blueznl »
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide
right here... )