ExamineDirectory with multiple patterns?

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

ExamineDirectory with multiple patterns?

Post by Mistrel »

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?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

No, it's not possible.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Anyone know if this is planned for a future release?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

yep, its planned since 2005. :P

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I know, I was bumping the request by making it look innocent. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

It would be good to have this feature implemented.
The pattern for ExamineDirectory() should be similar to the pattern of OpenFileRequester():

Code: Select all

ExamineDirectory(0, "C:\pictures\", "*.bmp|*.jp?g|*.png")
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.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

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()
Post Reply