Task

Walk a given directory tree and print files matching a given pattern.


Note: This task is for recursive methods.   These tasks should read an entire directory tree, not a single directory.


Note: Please be careful when running any code examples found here.



Related task

   Walk a directory/Non-recursively   (read a single directory). 


#include "dir.bi"
 
Sub listFiles(Byref filespec As String, Byval attrib As Integer)
    Dim As Integer count = 0
    Dim As String filename = Dir(filespec, attrib)
    Do While Len(filename) > 0
        count += 1
        Print filename
        filename = Dir()
    Loop
    Print !"\nArchives count:"; count
End Sub
 
Dim As String mylist = "C:\FreeBASIC\""
Print "Directories:"
listFiles(mylist & "*", fbDirectory)
Print
Print "Archive files:"
listFiles(mylist & "*", fbArchive)
Sleep