Based on this How to batch Check geometry in ArcGIS for a list of datasets from a CSV? code, i'm trying to extract the mosaic dataset path's within multiple folders. If i directly provide the mosaic_dataset path instead of fcs, the code works fine. But don't know why it's not reading the path from csv file. This is the path in the csv file(row 0) D:\QAQC\Test.gdb\Aus_Geology.gdb\250K_Geology. If i copy and replace fcs with exact same thing, the code works.

import csv
import arcpy
csvpath = r"D:\QAQC\Open2.csv"
with open(csvpath, "r") as csvfile:
    fcs = [r[0] for r in csv.reader(csvfile)]

This is the error i am getting

File "", line 6, in File "c:\program files\arcgis\desktop10.3\arcpy\arcpy\management.py", line 11099, in ExportMosaicDatasetPaths raise e RuntimeError: Object: Error in executing tool

1 Answer 1


It would be helpful if you gave more details about the contents of your CSV file (is there more than one line?) and about what error you are seeing.

The main issue I see with your code is that you are making the variable fcs a list, and the arcpy tool you call is looking for a single input object. Passing a list might cause an error (I am not sure as you do not give details about the error message). If you CSV only contains one line, just modify the fcs variable like so:

fcs = str([r[0] for r in csv.reader(csvfile)][0])

If you have more than one line, you would need to put your arcpy tool in a loop to iterate over the items in the list.

Here's a complete code block that includes looping over the lines of your CSV:

import csv
import arcpy
from os import path
csvpath = r"D:\QAQC\Open2.csv"
csvdir = path.split(csvpath)[0]
with open(csvpath, "r") as csvfile:
    fcs = [r[0] for r in csv.reader(csvfile)]
tables = []
for fc in fcs:
    mosaicname = path.split(fc)[1] + '.dbf'
    tablefile = path.join(csvdir, mosaicname)
    arcpy.ExportMosaicDatasetPaths_management(fc, tablefile)
arcpy.Merge_management(tables, r'D:\Test\Paths.dbf')
for eachTable in tables:
  • I've tried with the code you've provided. It says "Invalid syntax error". And i've edited the question and added the error i am getting. Could you have a look
    – joseph_k
    Commented Apr 27, 2016 at 9:03
  • My apologies, I had a typo on the code. It was missing an opening bracket. Can you try again with the line in my edited answer? Commented Apr 27, 2016 at 13:17
  • Oh. Worked. I know it's a lot to ask. But if could you tell me how to loop for a list, like D:\QAQC\A.gdb\ggg and the next line will be D:\QAQC\B.gdb\kkk in that csv. Will be greatly useful.
    – joseph_k
    Commented Apr 27, 2016 at 16:05
  • See my edit above. The code first makes a DBF for each mosaic dataset you have in the CSV, then merges all tables into a single DBF. I assume that is what you want. If you want each mosaic dataset in a separate DBF, just leave out the last 3 lines. Commented Apr 27, 2016 at 16:07
  • Thanks a lot mate. Immensely helpful. So is this how i've to loop through the lines in a CSV ? And, though the code has created individual tables while merging it's showing this error "AttributeError: 'module' object has no attribute 'merge'"
    – joseph_k
    Commented Apr 27, 2016 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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