I have this code that converts my csv file into a txt version of an xml file.. How can I edit this to convert all files in a folder?
import csv
csvFile = 'path\to\input\123.csv'
xmlFile = 'path\to\output\123.txt'
csvData = csv.reader(open(csvFile))
xmlData = open(xmlFile, 'w')
rowNum = 0
for row in csvData:
if rowNum == 0:
tags = row
# replace spaces w/ underscores in tag names
for i in range(len(tags)):
tags[i] = tags[i].replace(' ', '_')
else:
xmlData.write('<products_joined>' + "\n")
for i in range(len(tags)):
xmlData.write(' ' + '<' + tags[i] + '><![CDATA[' \
+ row[i] + ']]></' + tags[i] + '>' + "\n")
xmlData.write('</products_joined>' + "\n")
rowNum +=1
xmlData.close()