Skip to content

Instantly share code, notes, and snippets.

@timofey260
Created November 1, 2023 20:24
Show Gist options
  • Save timofey260/8bb2669847122dba4552be3afdcd4876 to your computer and use it in GitHub Desktop.
Save timofey260/8bb2669847122dba4552be3afdcd4876 to your computer and use it in GitHub Desktop.
counts code length in characters and lines for each argument
import sys
import os
filetypes = [".py", ".json"]
# usage: countsize.py [dir, ...]
# example: countsize.py F:\Desktop\project F:\Desktop\project\files
args = sys.argv
linesamount = 0
charsamount = 0
for i in args[1:]:
for filename in os.listdir(i):
f = os.path.join(i, filename)
if os.path.isfile(f):
_, ex = os.path.splitext(filename)
if ex in filetypes:
print(f"opened {f}, ", end="")
file = open(f, "r").read()
ca = len(file)
la = file.count("\n")
print(f"chars: {ca}; lines {la}")
linesamount += la
charsamount += ca
print("Lines written: ", linesamount)
print("Chars written: ", charsamount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment