Walk a directory/Recursively: Difference between revisions

/* {{header|PureBasic}} Added PureBasic
m (Forgot to change header)
(/* {{header|PureBasic}} Added PureBasic)
Line 642:
''Note:'' To include only ''files'' instead of directories too each of the above needs an additional<code>Where-Object</code> filter:
<lang powershell>| Where-Object { !$_.PSIsContainer }</lang>
 
=={{header|PureBasic}}==
<lang PureBasic>Procedure.s WalkRecursive(dir,path.s,Pattern.s="\.txt$")
Static RegularExpression
If Not RegularExpression
RegularExpression=CreateRegularExpression(#PB_Any,Pattern)
EndIf
While NextDirectoryEntry(dir)
If DirectoryEntryType(dir)=#PB_DirectoryEntry_Directory
If DirectoryEntryName(dir)<>"." And DirectoryEntryName(dir)<>".."
If ExamineDirectory(dir+1,path+DirectoryEntryName(dir),"")
WalkRecursive(dir+1,path+DirectoryEntryName(dir)+"\",Pattern)
FinishDirectory(dir+1)
Else
Debug "Error in "+path+DirectoryEntryName(dir)
EndIf
EndIf
Else ; e.g. #PB_DirectoryEntry_File
If MatchRegularExpression(RegularExpression,DirectoryEntryName(dir))
Debug DirectoryEntryName(dir)
EndIf
EndIf
Wend
EndProcedure
 
;- Implementation; Find all .log-files in the C:\Windows tree
ExamineDirectory(1,"C:\WINDOWS\","")
WalkRecursive(1,"C:\WINDOWS\","\.log$")
FinishDirectory(1)</lang>
 
=={{header|Python}}==
Anonymous user