merge multiple tables with Merge_management?

6891
11
08-23-2011 11:58 AM
leewalston
New Contributor
Hello,

Can anyone tell me how to merge multiple dbf tables from the same folder into one large dbf table?  Let's say I have 5 dbf tables with identical schema in the following folder:  "C:\\Data\\Tables".  I've tried listing the tables and using that object as the input, but to no avail. I haven't found much help on other forums as well...

This sounds so simple, but for some reason I can't figure it out:

gp.workspace = "C:\\Data\\Tables"
tablelist = gp.ListTables("*")
gp.Merge_management(tablelist, "C:\\Data\\Tables\\merged.dbf")

Thanks for any input.
Tags (2)
0 Kudos
11 Replies
RDHarles
Occasional Contributor
You can do it in Arc10:

import arcpy, os
arcpy.env.workspace = "c:/junk"
tableList = arcpy.ListTables()
arcpy.Merge_management(tableList, "easy.dbf")
In 9.x, it's much more involved.

What version of Arc are you using?
0 Kudos
MatthiasAbele
New Contributor II
Hallo,

that is a nice code snippet...I am new to python; how can I make a skript from this?

Yours

Matthias
0 Kudos
RDHarles
Occasional Contributor
Hallo,

that is a nice code snippet...I am new to python; how can I make a skript from this?

Yours

Matthias


The piece of code above will run as it is.  You just need to copy it and save it as a file (e.g. script.py).
There are many ways/places to run python scripts.
Here's a link that describes one way to do it:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_creating_script_tools/...
0 Kudos
MatthiasAbele
New Contributor II
Thank you, I will read through this...I tried your script with norma (yellow) tables...it was working very nicely; but with dbf tables...it is not working for me.

Here is the message:
>>> import arcpy, os
... arcpy.env.workspace = "C:\Users\admin\Desktop"
... tableList = arcpy.ListTables()
... arcpy.Merge_management(tableList, "easy.shp")
... 
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Datasets: Dataset fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p0avk0p2_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p2avk0p4_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p4avk0p6_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p6avk0p8_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p8avk1p0_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p0avk1p2_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p2avk1p4_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p4avk1p6_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p6avk9p0_final.dbf does not exist or is not supported Failed to execute (Merge). 
>>> 


What could be the reason?

Thanx,

Matthias
0 Kudos
RDHarles
Occasional Contributor
Thank you, I will read through this...I tried your script with norma (yellow) tables...it was working very nicely; but with dbf tables...it is not working for me.

Here is the message:
>>> import arcpy, os
... arcpy.env.workspace = "C:\Users\admin\Desktop"
... tableList = arcpy.ListTables()
... arcpy.Merge_management(tableList, "easy.dbf")
... 
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Datasets: Dataset fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p0avk0p2_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p2avk0p4_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p4avk0p6_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p6avk0p8_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p8avk1p0_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p0avk1p2_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p2avk1p4_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p4avk1p6_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p6avk9p0_final.dbf does not exist or is not supported Failed to execute (Merge). 
>>> 
What could be the reason?

Thanx,

Matthias


At first glance, you have your slashes wrong in the workspace path, try this:
"C:/Users/admin/Desktop"

Also, the output file should either be have a .dbf extension on it (my mistake) or should point to a file geodatabase like this:
test.gdb/table
0 Kudos
MatthiasAbele
New Contributor II
Thanx, but I still get an error:
>>> import arcpy, os
... arcpy.env.workspace = "C:/Users/admin/Desktop"
... tableList = arcpy.ListTables()
... arcpy.Merge_management(tableList, "easy.dbf")
... 
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Datasets: Dataset fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p0avk0p2_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p2avk0p4_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p4avk0p6_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p6avk0p8_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg0p8avk1p0_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p0avk1p2_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p2avk1p4_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p4avk1p6_final.dbf;fglr_o_fr_500m_C280_RNW_u_v_vBETRAG_neu_flussschlauch_vg1p6avk9p0_final.dbf does not exist or is not supported Failed to execute (Merge). 
>>> 
0 Kudos
RDHarles
Occasional Contributor
Thanx, but I still get an error:


Not sure why it won't work for you???  I ran it from 2 different environments and it worked fine.
From where are you running this script?
0 Kudos
MatthiasAbele
New Contributor II
Hallo,

I ran it serveral times...with .info-tables it is working perfectely. But with info-tables, the file name length seems to be limited. Therefor I will have to work with .dbf-tables.
With dbf-tables I always get error messages, independently of the file name length:
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Datasets: Dataset fglr78.dbf;fglrjk.dbf does not exist or is not supported Failed to execute (Merge). 


Attached are 3 out of many dbfs I would like to merge. Perhaps you can try it.

Yours,

Matthias
0 Kudos
RDHarles
Occasional Contributor
I just ran this script:

import arcpy, os
arcpy.env.workspace = "c:/junk/dbf/mergeEasy"
tableList = arcpy.ListTables()
arcpy.Merge_management(tableList, "easy.dbf")
...on the data you posted and it worked fine for me.
Not sure what your doing differently on your end?

Also, what do you mean by the difference between .info-tables & info-tables? (.dbf vs. file geodatabase)?
0 Kudos