Hello,
I'm looking to build a Python script that will take the file names of PDFs in a certain folder directory and copy them to a new FGDB table. I am able to print these file names using the following simple script:
import os, arcpy
arcpy.env.workspace = r'\\ch_gis\gis\......'
files = arcpy.ListFiles()
for f in files:
print f
and get the expected outcome:
However, I am having troubles trying to copy these file names to an empty FGDB table. Any assistance would be appreciated.
Thanks,
Craig
Solved! Go to Solution.
untested
import arcpy
import os
arcpy.env.workspace = r'\\ch_gis\gis\......'
files = arcpy.ListFiles()
for f in files:
print(f)
fields = ['your field']
cursor = arcpy.da.InsertCursor(r'path to your table', fields)
for f in files:
cursor.insertRow((f))
del cursor
What do you mean by copy them exactly? as in just add the filepath strings to a column in the table? Does the table and column already exist? I'd say just an insert cursor.
David,
To clarify, I do have a table and field already created. I'm looking to just copy the file names (i.e. WP20150014.pdf) to the table. Thanks for the suggestion of the insert cursor.
untested
import arcpy
import os
arcpy.env.workspace = r'\\ch_gis\gis\......'
files = arcpy.ListFiles()
for f in files:
print(f)
fields = ['your field']
cursor = arcpy.da.InsertCursor(r'path to your table', fields)
for f in files:
cursor.insertRow((f))
del cursor
Thanks David. This works great. The only change that I made to your code was to add brackets around 'f' so it read: cursor.insertrow([f])