Dec-25-2018, 07:54 AM
I don't understand the issue, but csvFilename should not be
That said, I would better try a shorter way using
__pycache__
. I seems to me that lines 14-29 should be indented in the for loop.That said, I would better try a shorter way using
shutil.copyfileobj
#! python3 # removecsvheader.py - Removes the header from all CSV files in the current working directory import csv, os import shutil os.makedirs('headerRemoved', exist_ok=True) # loop through every file in the current working directory. for csvFilename in os.listdir('.'): if not csvFilename.endswith('.csv'): continue # skip non-csv files print('Removing header from ' + csvFilename + '...') targetFilename = os.path.join('headerRemoved', csvFilename) with open(csvFilename) as ifo, open(targetFilename, "w") as ofo: ifo.readline() shutil.copyfileobj(ifo, ofo)