Skip to content

Instantly share code, notes, and snippets.

@KenjiOhtsuka
Created May 21, 2018 02:12
Show Gist options
  • Save KenjiOhtsuka/bfaa3b87d7c705d24c79e35b55ff62d0 to your computer and use it in GitHub Desktop.
Save KenjiOhtsuka/bfaa3b87d7c705d24c79e35b55ff62d0 to your computer and use it in GitHub Desktop.
Get Children in File System with Kotlin
/**
* Sample code to handle file system
*/
import java.io.File
/**
* Get all sub file objects in the directory.
*/
fun sample1(path: String): Array<File> {
val f = File(String)
return f.listFiles()
}
/**
* Iterate files in the directory.
*/
fun sample2(path: String, block: File.() -> Unit) {
val d = File(path)
for (file in d.listFiles()) {
block()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment