Last active
September 5, 2017 08:42
-
-
Save Headline/b56537696fa128fcafb3c061e79c181e to your computer and use it in GitHub Desktop.
Revisions
-
Headline revised this gist
Sep 5, 2017 . 1 changed file with 20 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,23 @@ import os import os.path import mimetypes import locale def get_clean_path(array): somestr = "" for x in range(0, len(array) - 1): somestr += array[x] + "\\" return somestr def get_line_count(fname): if not os.path.isfile(fname): return 0 with open(fname, errors="ignore") as f: i = 0 for i, l in enumerate(f): pass return i + 1 def is_plain_text(file): if (mimetypes.guess_type(file)[0] == 'text/plain'): @@ -26,9 +30,13 @@ def is_plain_text(file): count = 0 for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: current = dirpath + "\\" + filename if is_plain_text(current): line_count = get_line_count(current) count += line_count print("Adding: " + current + "(" + str(line_count) + ")") locale.setlocale(locale.LC_ALL, 'english') output = locale.format('%d', count, grouping=True) # returns '4,294,967,296' print("Total lines for all files: " + output) -
Headline created this gist
Sep 5, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import os import mimetypes def get_clean_path(array): somestr = "" for x in range(0, len(array) - 1): somestr += array[x] + "\\" return somestr def get_line_count(path): count = 0 file = open(path, "r") row = file.readlines() for line in row: count += 1 return count def is_plain_text(file): if (mimetypes.guess_type(file)[0] == 'text/plain'): return True else: return False path = get_clean_path(os.path.realpath(__file__).split("\\")) count = 0 for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: current = dirpath + filename if (is_plain_text(current)): print("Adding: " + current) count += get_line_count(current) print("Total lines for all files: " + str(count))