Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File
- fun grepFile(file: File, pattern: Regex) {
- file.forEachLine {
- if (pattern.matches(it)) {
- println(it)
- }
- }
- }
- fun grepFile(path: String, pattern: String) {
- grepFile(File(path), Regex(pattern))
- }
- fun grepFiles(root: File, suffix: String, pattern: Regex) {
- if (root.isFile && root.name.endsWith(suffix)) {
- grepFile(root, pattern)
- return
- }
- if (root.isDirectory) {
- for (f in root.listFiles()) {
- grepFiles(f, suffix, pattern)
- }
- }
- }
- fun grepFiles(rootPath: String, suffix: String, pattern: String) {
- grepFiles(File(rootPath), suffix, Regex(pattern))
- }
- fun main(args: Array<String>) {
- grepFiles("src", ".kt", "\\{");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement