ExamineDirectory with multiple patterns?
ExamineDirectory with multiple patterns?
Is it possible to use ExamineDirectory with multiple patterns? I tried several combinations and wasn't make to make it work. I'm currently filtering by passing my own pattern string and comparing each file myself. I'm just curious if there is some native functionality that's not described in the documentation?
It would be good to have this feature implemented.
The pattern for ExamineDirectory() should be similar to the pattern of OpenFileRequester():
In the requester, you can also use multiple pattern by separating them with a | vertical bar.
This would even increase consistency within PureBasic; and obviously, consistency is an important point for Fred and Freak.
The pattern for ExamineDirectory() should be similar to the pattern of OpenFileRequester():
Code: Select all
ExamineDirectory(0, "C:\pictures\", "*.bmp|*.jp?g|*.png")
This would even increase consistency within PureBasic; and obviously, consistency is an important point for Fred and Freak.
PB 4.30
Code: Select all
onErrorGoto(?Fred)
Code: Select all
Procedure Findfiles(*fn,StartDirectory.s,pattern.s,Recursive=1)
Static strFiles.s,ct1,ptc,bPattern
Protected k,ct
If Not bPattern
tpattern.s = RemoveString(pattern,"*")
ptc = CountString(tpattern,"|")
Static Dim pt.s(20)
For k=1 To ptc+1
pt(k-1) = StringField(tpattern,k,"|")
Debug pt(k-1)
Next
bPattern = #True
EndIf
mDir = ExamineDirectory(#PB_Any, StartDirectory, "*.*")
If mDir
While NextDirectoryEntry(mDir)
If DirectoryEntryType(mDir) = #PB_DirectoryEntry_File
Directory$ = StartDirectory
FileName.s = DirectoryEntryName(mDir)
ct=0
While ct <= ptc
If FindString(FileName,pt(ct), 1)
FullFileName.s = StartDirectory + "\" + FileName
If CallFunctionFast(*fn,FullFileName) = 0
Break 2
EndIf
Ct1 + 1
EndIf
ct+1
Wend
Else
tdir$ = DirectoryEntryName(mDir)
If tdir$ <> "." And tdir$ <> ".."
If Recursive = 1
Findfiles(*fn,StartDirectory + "\" + tdir$,"")
EndIf
EndIf
EndIf
Wend
FinishDirectory(mDir)
EndIf
ProcedureReturn ct1
EndProcedure
Global NewList myfiles.s()
Procedure MyCallBack(ResultString.s)
PrintN(ResultString)
ProcedureReturn #True
EndProcedure
OpenConsole()
count = FindFiles(@MyCallBack(),"C:\Pictures", "*.bmp|*.jpg|*.png",1)
PrintN(Str(count))
Input()