My code

import arcpy, os, shutil, re
from arcpy import env
arcpy.env.workspace = "R:\GIS_Data\Earthquake_Data\Updates\Eq_updates.mdb"
path = r"R:\GIS_Data\Earthquake_Data\Updates"
In_path = r"R:\GIS_Data\Earthquake_Data\Updates\OGS_Auto_Updates\csv"
Out_path = r"R:\GIS_Data\Earthquake_Data\Updates\OGS_Auto_Updates\dbf_new"
#gdb_name = r"R:\GIS_Data\Earthquake_Data\Updates\Eq_updates.mdb"
connect = "\\"

# convert csv to dbf in a separate folder
# Local variables inputs and outputs: filenames

for filenames in os.listdir(In_path):
    arcpy.TableToTable_conversion(filenames, r"R:\GIS_Data\Earthquake_Data\Updates\Eq_updates.mdb", os.path.splitext(filenames)[0] + ".dbf")
    print("Successfully converted" + os.path.splitext(csv)[0] + ".csv to " + os.path.splitext(csv)[0] + ".dbf")

the error: File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\conversion.py", line 2249, in TableToTable raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rows: Dataset 2000-2009.csv does not exist or is not supported Failed to execute (TableToTable).

Am I missing a import or other command? (very new at python)

  • Do the rules allowed for file names permit 1) starting with a number and 2 including a -? – NSD Dec 20 '18 at 20:04

There are several issues with the code:

You should add a file extension check after os.listdir to make sure your only looking at .csv files:

for filenames in os.listdir(In_path):
    if filenames.endswith('.csv'):
        # continue on with code

Next, your saving a .dbf to a .mdb file which is not possible. Change the out path to the Out_path variable.

Finally, since the env workspace is pointing to the mdb the in_table parameters needs the full file path, update the table to table statement to this:

# exporting to folder
arcpy.TableToTable_conversion(os.path.join(In_path, filenames), Out_path, os.path.splitext(filenames)[0] + ".dbf")
| improve this answer | |
  • Thanks, I added your suggestions: 1st though I had removed the csv check because that is all that is in there, but safety is always a good thing so I put it back. 2nd the conversion as you have it doesn't tell it to become a dbf. So I tried adding + .dbf before the final ). New Error message: "File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\conversion.py", line 2249, in TableToTable raise e ExecuteError: ERROR 000354: The name contains invalid characters Failed to execute (TableToTable)." – NSD Dec 20 '18 at 17:58
  • I updated the code snippet to include the .dbf file extension again. The new error suggest an invalid file character maybe a space or some other character in the .csv filename. – artwork21 Dec 20 '18 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.