title: Python Convert all csv files in folder to txt
body: <p>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?</p>
  
  <pre><code>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('&lt;products_joined&gt;' + "\n")
          for i in range(len(tags)):
              xmlData.write('    ' + '&lt;' + tags[i] + '&gt;&lt;![CDATA[' \
                            + row[i] + ']]&gt;&lt;/' + tags[i] + '&gt;' + "\n")
          xmlData.write('&lt;/products_joined&gt;' + "\n")
  
      rowNum +=1
  
  xmlData.close()
  </code></pre>