#!/usr/bin/python
# -*- coding: utf-8 -*-
#import codecs
import os, sys
import re
import time
from collections import Counter;

# sed "s/.*\<DIR\>.*//"g fulllist.txt | sed "s/.*Directory of.*//"g | grep --only-matching -E "[a-z,A-Z,0-9]\.[a-z,A-Z,0-9]{3,4}\s$" | grep --only-matching -E "[a-z,A-Z,0-9]{3,4}\s$" > list.txt; perl -p -i -e "tr/A-Z/a-z/" list.txt

sourceFile = "list.txt"
directory = "/home/comstock/Documents/python"
inputFilename = directory + "/" + sourceFile

print "DEBUG: Input filename = " + inputFilename
out = open ("fileTypesOut.txt",'w')
outCount = open ("fileTypeCounts.txt",'w')
gaggle ={""}

cnt = Counter ();

# the following counts occurance of the 3- or 4-character file extensions in inputFilename
for line in open (inputFilename, 'r'):
  for word in line.split ():
    cnt [word] += 1

# print(cnt, file=outCount)
print >> outCount, cnt
# outCount.write(cnt)
# the following generates a list of file types found in list.txt, which has become uneccessary as the counting routine above generates a list of filetypes found, and the counts for each.
with open(inputFilename,'r') as jello:
    for line in jello:
        line = line.rstrip()       
        gaggle.add(line)        
out.write('\n'.join(gaggle))
