Created
November 1, 2023 20:24
-
-
Save timofey260/8bb2669847122dba4552be3afdcd4876 to your computer and use it in GitHub Desktop.
counts code length in characters and lines for each argument
This file contains 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 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