Skip to content

Instantly share code, notes, and snippets.

@sshh12
Last active March 25, 2018 18:48
Show Gist options
  • Save sshh12/17c07015d88824e601fff05f22a9df23 to your computer and use it in GitHub Desktop.
Save sshh12/17c07015d88824e601fff05f22a9df23 to your computer and use it in GitHub Desktop.
Count total lines of code
import glob
import os
## Count
exts = ['.py', '.js', '.md', 'java', '.html', '.css', '.pde']
def count_lines(fn):
i = 0
with open(fn, 'r', encoding="utf8") as code:
for _ in code:
i += 1
return i
## Run
total = 0
for filename in glob.iglob('./**/*', recursive=True):
fn, ext = os.path.splitext(filename)
if ext.lower() in exts and "node_modules" not in fn and "\\plugins\\" not in fn and "\\platforms\\" not in fn:
print(fn)
total += count_lines(filename)
print(total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment