Created
May 21, 2018 02:12
-
-
Save KenjiOhtsuka/bfaa3b87d7c705d24c79e35b55ff62d0 to your computer and use it in GitHub Desktop.
Get Children in File System with Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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