I have a list of files I iterate through to merge them all into one .csv file:
with open('C:\\TODAY.csv', 'w') as f_obj:
rows = []
files = os.listdir('C:\RAW\\')
for f in files:
if fnmatch.fnmatch(f, '*.csv') and not fnmatch.fnmatch(f, 'TODAY.CSV'):
print f
rows.append(open(os.path.join('C:\\RAW_OTQ\\', f)).readlines())
iter = izip_longest(*rows)
for row in iter:
f_obj.write(','.join([field.strip() for field in row if field is not None]) + '\n')
This works as intended, however it has the most recent date in the left most column. What I want is to have it reversed, so the oldest is read first.
This could be achieved if it starts the iteration at the end and works backwards, as this will just reverse the order in which they are appended to the list, and then the list will, in essence, be an exact reverse of what it is currently.
How would I go about reversing the order in which the files are read.
Please note: I don't want the individual files to be read backwards, but just reverse the order in which the files are read.