import csv
import xlwt
import os
import sys
#import openpyxl

# Look for input file in same location as script file:
inputfilename = os.path.join(os.path.dirname(sys.argv[0]), 'book2.txt')
# Strip off the path
basefilename = os.path.basename(inputfilename)
# Strip off the extension
basefilename_noext = os.path.splitext(basefilename)[0]
# Get the path of the input file as the target output path
targetoutputpath = os.path.dirname(inputfilename)
# Generate the output filename
outputfilename =  os.path.join(targetoutputpath, basefilename_noext+'.xls')

# Create a workbook object
workbook = xlwt.Workbook()
# Add a sheet object
worksheet = workbook.add_sheet(basefilename_noext, cell_overwrite_ok=True)

# Get a CSV reader object set up for reading the input file with tab delimiters
datareader = csv.reader(open(inputfilename, 'r'), delimiter=',', quotechar='"')

# Process the file and output to Excel sheet
for rowno, row in enumerate(datareader):
    for colno, colitem in enumerate(row):
        worksheet.write(rowno, colno, colitem)

# Write the output file.

In the above code i can convert only one file in singel folder , Please help me am new to coding

  1. I want to serach the *.txt file in subfolders
  2. Append to single excel file