Hi there,
I have run the code below on multiple occasions with no problems, but lately have been running into an error. I use arcpy.conversion.ExportTableto bring csvs housed on a network drive to tables in my working gdb (Code Below). I have tried the following solutions I found on Esri Community and GISStackExchange.
I have also restarted my computer. When I check the output in the GUI, it seems some of the rows/observations in the csv are exported to the gdb before the error is returned. Any suggestions are more than welcome, but please check the error handling and previous attempts. Thank you!
# Step 4. Create tables from csv files
# set workspace to gdb
arcpy.env.workspace = gdb
for in_table in in_tables_ed:
print(f"Processing {in_table}...")
# Check if the input file exists
if not os.path.exists(in_table):
print(f"Error: {in_table} does not exist")
continue
# Resolve output name
out_name = os.path.basename(in_table).replace('.csv', '')
# Check if the table already exists in the geodatabase
if arcpy.Exists(out_name):
print(f"Table {out_name} already exists in the geodatabase. Skipping...")
continue
try:
# Export the table
arcpy.conversion.ExportTable(in_table, out_name)
print(f"Converted {in_table} to table {out_name} in {gdb}")
except arcpy.ExecuteError:
print(f"Failed to export {in_table}. Error: {arcpy.GetMessages(2)}")
except Exception as e:
print(f"An unexpected error occurred: {e}")