Walk a directory/Non-recursively: Difference between revisions

Added Kotlin
m (→‎{{header|Sidef}}: updated code)
(Added Kotlin)
Line 672:
 
walkDirectory(dir, '\\.txt$');</lang>
 
=={{header|Kotlin}}==
<lang scala>// version 1.1.2
 
import java.io.File
 
fun walkDirectory(dirPath: String, pattern: Regex): List<String> {
val d = File(dirPath)
require(d.exists() && d.isDirectory())
return d.list().filter { it.matches(pattern) }
}
 
fun main(args: Array<String>) {
val r = Regex("""^a.*\.h$""") // get all C header files beginning with 'a'
val files = walkDirectory("/usr/include", r)
for (file in files) println(file)
}</lang>
Sample output (Ubuntu v14.04):
{{out}}
<pre>
argp.h
alloca.h
ar.h
aliases.h
autosprintf.h
aio.h
assert.h
argz.h
</pre>
 
=={{header|Lasso}}==
9,485

edits