Walk a directory/Recursively: Difference between revisions

Added Wren
(Added a general comment.)
(Added Wren)
Line 2,687:
Next
End Sub</lang>
 
=={{header|Wren}}==
{{libheader|Wren-pattern}}
<lang ecmascript>import "io" for Directory, File
import "/pattern" for Pattern
 
var walk // recursive function
walk = Fn.new { |dir, pattern, found|
if (!Directory.exists(dir)) Fiber.abort("Directory %(dir) does not exist.")
var files = Directory.list(dir)
for (f in files) {
var path = dir + "/%(f)"
if (File.exists(path)) { // it's a file not a directory
if (pattern.isMatch(f)) found.add(f)
} else {
walk.call(path, pattern, found)
}
}
}
 
// get all C header files beginning with 'va' or 'vf'
var p = Pattern.new("v[a|f]+0^..h", Pattern.whole)
var found = []
walk.call("/usr/include", p, found)
for (f in found) System.print(f)</lang>
 
{{out}}
<pre>
valarray_after.h
valarray_array.h
valarray_before.h
vfio.h
vfio_ccw.h
valgrind.h
values.h
vfs.h
validate.h
</pre>
 
=={{header|zkl}}==
9,479

edits