I am using arcpy.ListFiles(filename*.csv) to automatically find CSV tables in my workspace folder. I am then using ''.join() to turn the list result items into a string to be used as a parameter in an arcpy process.
I have three CSV files in my workspace that are all named like this:
“AGOL_export_users_<date>.csv”
I am trying to use the string result in an arcpy.Merge_management(inputs, output, {field_mappings}) process. The ArcGIS online help for Merge shows this inputs example: ["majorrds.shp", "Habitat_Analysis.gdb/futrds"], where square brackets, double quotes and commas are used to list the items.
My “ListFiles” result when printed looks like this:
['AGOL_export_users_2017_06_01.csv', 'AGOL_export_users_2017_07_03.csv', 'AGOL_export_users_2017_08_01.csv']
My “join” result when printed looks like this:
["AGOL_export_users_2017_06_01.csv", "AGOL_export_users_2017_07_03.csv", "AGOL_export_users_2017_08_01.csv"]
This is my script:
import arcpy, os, sys, time
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\Temp\pythonAGOL"
listAGOLusers = arcpy.ListFiles("AGOL_export_users*.csv")
AGOLusers = ("[\"" + '", "'.join(listAGOLusers) + "\"]")
listFGDB = arcpy.ListWorkspaces("AGOL*", "FileGDB")
FGDB = (''.join(listFGDB))
MergedMonthsTable = FGDB + "\\MergedMonthsTable"
arcpy.Merge_management(AGOLusers, MergedMonthsTable)
del listAGOLusers, AGOLusers, listFGDB, FGDB, MergedMonthsTable
When I run the script, I get this error message:
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Datasets: Dataset '["AGOL_export_users_2017_06_01.csv", "AGOL_export_users_2017_07_03.csv", "AGOL_export_users_2017_08_01.csv"]' does not exist or is not supported
When I list each CSV file as a local variable, the Merge script, shown below, works fine.
agolTable1 = "AGOL_export_users_2017_06_01.csv"
agolTable2 = "AGOL_export_users_2017_07_03.csv"
agolTable3 = "AGOL_export_users_2017_08_01.csv"
arcpy.Merge_management([agolTable1,agolTable2,agolTable3], MergedMonthsTable)
Does anyone see what I am doing incorrectly with ListFiles and join in my script?
Your thoughts are much appreciated.
Thank you,
Joe