Select to view content in your preferred language

python script to copy table from one gdb to another gdb

1804
2
08-26-2022 05:48 AM
junaidjawaid
Occasional Contributor

I am trying to copy an SDE geodatabase table to a file geodatabase using a simple script copied below.

>>> destgdb= 'D:\Data\testAug_23_2022.gdb'
... arcpy.env.workspace= 'C:\Users\gis4\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\Connection to gisprd.sde'
... table = arcpy.ListTables("table1")
... arcpy.Copy_management(table,os.path.join(destgdb))

 

It is giving following error, can any point out what may be the issue in this script?

Runtime error
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py", line 4314, in Copy
raise e
RuntimeError: Object: Error in executing tool

0 Kudos
2 Replies
dslamb2022
Occasional Contributor

arcpy.ListTables() returns a list object. So you would need something like this:

table = arcpy.ListTables("table1")[0]

or

tables = arcpy.ListTables("table1")

table = tables[0]
junaidjawaid
Occasional Contributor

Added the suggestion in my script below but this is copying other tables as well, despite I have select the the targeted table from the list using the table index [0]. The table I am copying is a part of a relationship class, may this be the reason that the script is copying the other tables as well?

 

 

destgdb= 'D:\Data\testAug_23_2022.gdb'
... arcpy.env.workspace= 'C:\Users\gis4\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\Connection to gisprd.sde'
... table = arcpy.ListTables("table1")[0]
... arcpy.Copy_management(table,os.path.join(destgdb,table))

0 Kudos