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). 


 
Class Utils.File [ Abstract ]
{
 
ClassMethod WalkTree(pDir As %String = "", pMask As %String = "*.*") As %Status
{
	// do some validation
	If pDir="" Quit $$$ERROR($$$GeneralError, "No directory specified.")
 
	// search input directory for files matching wildcard
	Set fs=##class(%ResultSet).%New("%File.FileSet")
	Set sc=fs.Execute(pDir, pMask)
	While (fs.Next()) {
		Write !, fs.Name
		// sub-directory
		If fs.Type="D" Set sc=..WalkTree(fs.Name, pMask)
	}
 
	// finished
	Quit $$$OK
}
 
}
 