The source file you have will remain as dbf. You are not actually replacing it, but instead creating a new csv file. I think the problem is that writing to disk never happens. I suspect csv-writer is not flushing the file buffer.
Another problem that I see is that out_csv is created conditionally, so if you have another file in this directory with a different extension, you will run into problems.
Try using the context manager:
for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: if filename.endswith('.DBF'): csv_fn = filename[:-4]+ ".csv" with open(csv_fn,'wb') as csvfile: in_db = dbf.Dbf(os.path.join(dirpath, filename)) out_csv = csv.writer(csvfile) names = [] for field in in_db.header.fields: names.append(field.name) out_csv.writerow(names) for rec in in_db: out_csv.writerow(rec.fieldData) in_db.close()
The 'with' statement (context manager) will close the file and clear the buffer at the end, without explicitly requiring it.
source share