Search code examples
pythondbf

Extract Field Names and Types from DBF Files


I have about 100 DBF's that I need to move to SQL Server. Rather than trying to recreate the entire structure manually, I'd like to be able to pull out the field names and field types from the DBF files and create the associated tables in SQL Server. I know the types will be different, but this isn't a problem, I can map those. I'm using DBFRead but can't figure out how to extract the field information.


Solution

  • I am not familiar with DBFRead, but using my dbf library:

    import dbf
    
    table = dbf.Table('some_table_here.dbf')
    table.structure()
    # ['test C(40)', 'test2 N(3,0)', 'test3 C(3)', 'test4 M']