Skip to content

Instantly share code, notes, and snippets.

@delasy
Created April 23, 2024 14:18
Show Gist options
  • Save delasy/9231cbd0f2ae90368d54c70e9c6604e6 to your computer and use it in GitHub Desktop.
Save delasy/9231cbd0f2ae90368d54c70e9c6604e6 to your computer and use it in GitHub Desktop.
fn calcFileLines (filePath: str) int {
content := fs_readFileSync(filePath).str()
return content.lines().len
}
fn traverse (path: str) str[] {
entries := fs_scandirSync(path)
mut files: str[]
loop i := entries.len - 1; i >= 0; i-- {
entry := path + path_SEP + entries[i]
if fs_isFileSync(entry) {
files.push(entry)
} else {
f := traverse(entry)
files.merge(f)
}
}
return files
}
main {
files := traverse("./folder")
mut mostLines := 0
mut file := ""
loop i := files.len - 1; i >= 0; i-- {
lines := calcFileLines(files[i])
if lines > mostLines {
mostLines = lines
file = files[i]
}
}
print(file, mostLines)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment