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
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]
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))