I am using os.walk to find all the .dbf files and then a for loop utilizing the dbfpy module to convert each .dbf file to a .csv.
I am not receiving any errors but the files are not converting (staying as dbf files in path folder). Additionally, the dbf files are being emptied out (reduce to size of 0Kb) after the script is run. Note: the dbf files are stored in a subfolder of the Misc folder below.
- Code: Select all
from dbfpy import dbf
path = r"C:\Users\Stephen\Documents\House\Misc"
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), new= True)
out_csv = csv.writer(csvfile)
names = 
for field in in_db.header.fields:
for rec in in_db:
Any help appreciated....