Last active
August 29, 2015 14:09
-
-
Save SlayterDev/23d8fb59d5349903b97b to your computer and use it in GitHub Desktop.
Count the number of lines and files in a path. The script defaults to the current directory. Add a path as a command line argument to check another directory.
This file contains hidden or 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 os | |
| import sys | |
| numlines = 0 | |
| numFiles = 0 | |
| exclude = ['.o', '.bin', '.iso', '.img', '.log', '#', '.dre'] # file extensions to ignore | |
| def countLines(path): | |
| global numlines | |
| global numFiles | |
| global exclude | |
| for filename in os.listdir(path): | |
| if filename[0] == '.': | |
| continue | |
| flag = 0 | |
| for suffix in exclude: | |
| if filename.endswith(suffix): | |
| flag = 1 | |
| break | |
| if flag == 1: | |
| continue | |
| print("Checking " + filename) | |
| if os.path.isdir(filename): | |
| countLines(path + '/' + filename) | |
| else: | |
| numlines += sum(1 for line in open(path + '/' + filename)) | |
| numFiles += 1 | |
| def main(): | |
| path = '.' | |
| if len(sys.argv) > 1: | |
| path = sys.argv[1] | |
| print("Counting lines in path: " + path + "\n") | |
| countLines(path) | |
| print("[+] " + str(numlines) + " LOC " + str(numFiles) + " files.") | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment