def process_iis_directory(d): print('Processing IIS directory %s' % d) for entry in os.listdir(d): entry = os.path.join(d, entry) if entry.endswith('.gz'): print('Processing %s into CSV' % entry) with gzip.open(entry, 'rb') as uncompressed, \ io.BufferedReader(uncompressed) as buffered, \ io.TextIOWrapper(buffered, encoding='latin1') as infile, \ io.open(os.path.splitext(entry)[0] + '.csv', 'wb') as outfile, \ iis.IISSource(infile) as source, \ csv.CSVTarget(outfile) as target: for row in source: target.write(row)