Last active
November 21, 2018 19:29
-
-
Save ganzuul/7033ee06f519d2ef8193ae4af6b8ff07 to your computer and use it in GitHub Desktop.
Takes two directory names as arguments, iterates through the files in those directories, adds their content to lists of lists and prints what it has found.
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
import java.io.File | |
var file: MutableList<List<String>> = ArrayList() //list of lists | |
var file2: MutableList<List<String>> = ArrayList() //list of lists | |
fun main(args: Array<String>) { | |
file = readDir(args[0]) | |
file2 = readDir(args[1]) | |
for (e in file) println(e) | |
for (e in file2) println(e) | |
} | |
fun readDir(dir: String): MutableList<List<String>> { | |
val readFiles: MutableList<List<String>> = ArrayList() | |
File(dir).walkTopDown().forEach { | |
println(it.toString()) | |
if (File(it.toString()).extension == "txt") { //balks at directory names | |
readFiles.add(File(it.toString()).readLines()) //add list of lines to list of lists | |
} | |
} | |
return readFiles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment