Skip to main content
added 3 characters in body
Source Link
spk578
  • 1.5k
  • 1
  • 12
  • 27

So this should solve your question. This fundtion will list all the data sources found in any MXD file within a folder and it's subfolders. It'll save the CSV in the folder you specify to begin the search from.

Change the name of the CSV on line 22 if you need to.

The CSV is written with Path, FileName, FileType

import os
import csv
import arcpy

def ListMXDSources(path,extension):
  list_dir = []
  CountList = []
  MapList = []
  list_dir = os.listdir(path)
  count = 0
  for paths, dirctory, files in os.walk(path):
    for file in files:
        if file.endswith(extension): # eg: '.mxd'
          MapList.append(os.path.join(paths, file))
          print MapList
          for m in MapList:
                count += 1
                mxd = arcpy.mapping.MapDocument(m)
                ## --------- For each map list layers
                for lyr in arcpy.mapping.ListLayers(mxd):
                    with open("ListOfDataSources.csv", 'wb') as csvfile:
                        csvwriter = csv.writer(csvfile)
                        for dirpath, dirnames, filenames in arcpy.da.Walk(pathMapList):
                            for filename in filenames:
                                desc = arcpy.Describe(os.path.join(dirpath, filename))
                                csvwriter.writerow([desc.catalogPath, desc.name, desc.dataType])


#-------------Use below to call the function----------------#
ListMXDSources(path=r"ROOT FOLDER LOCATION",extension=".mxd")

So this should solve your question. This fundtion will list all the data sources found in any MXD file within a folder and it's subfolders. It'll save the CSV in the folder you specify to begin the search from.

Change the name of the CSV on line 22 if you need to.

The CSV is written with Path, FileName, FileType

import os
import csv
import arcpy

def ListMXDSources(path,extension):
  list_dir = []
  CountList = []
  MapList = []
  list_dir = os.listdir(path)
  count = 0
  for paths, dirctory, files in os.walk(path):
    for file in files:
        if file.endswith(extension): # eg: '.mxd'
          MapList.append(os.path.join(paths, file))
          print MapList
          for m in MapList:
                count += 1
                mxd = arcpy.mapping.MapDocument(m)
                ## --------- For each map list layers
                for lyr in arcpy.mapping.ListLayers(mxd):
                    with open("ListOfDataSources.csv", 'wb') as csvfile:
                        csvwriter = csv.writer(csvfile)
                        for dirpath, dirnames, filenames in arcpy.da.Walk(path):
                            for filename in filenames:
                                desc = arcpy.Describe(os.path.join(dirpath, filename))
                                csvwriter.writerow([desc.catalogPath, desc.name, desc.dataType])


#-------------Use below to call the function----------------#
ListMXDSources(path=r"ROOT FOLDER LOCATION",extension=".mxd")

So this should solve your question. This fundtion will list all the data sources found in any MXD file within a folder and it's subfolders. It'll save the CSV in the folder you specify to begin the search from.

Change the name of the CSV on line 22 if you need to.

The CSV is written with Path, FileName, FileType

import os
import csv
import arcpy

def ListMXDSources(path,extension):
  list_dir = []
  CountList = []
  MapList = []
  list_dir = os.listdir(path)
  count = 0
  for paths, dirctory, files in os.walk(path):
    for file in files:
        if file.endswith(extension): # eg: '.mxd'
          MapList.append(os.path.join(paths, file))
          print MapList
          for m in MapList:
                count += 1
                mxd = arcpy.mapping.MapDocument(m)
                ## --------- For each map list layers
                for lyr in arcpy.mapping.ListLayers(mxd):
                    with open("ListOfDataSources.csv", 'wb') as csvfile:
                        csvwriter = csv.writer(csvfile)
                        for dirpath, dirnames, filenames in arcpy.da.Walk(MapList):
                            for filename in filenames:
                                desc = arcpy.Describe(os.path.join(dirpath, filename))
                                csvwriter.writerow([desc.catalogPath, desc.name, desc.dataType])


#-------------Use below to call the function----------------#
ListMXDSources(path=r"ROOT FOLDER LOCATION",extension=".mxd")
Source Link
spk578
  • 1.5k
  • 1
  • 12
  • 27

So this should solve your question. This fundtion will list all the data sources found in any MXD file within a folder and it's subfolders. It'll save the CSV in the folder you specify to begin the search from.

Change the name of the CSV on line 22 if you need to.

The CSV is written with Path, FileName, FileType

import os
import csv
import arcpy

def ListMXDSources(path,extension):
  list_dir = []
  CountList = []
  MapList = []
  list_dir = os.listdir(path)
  count = 0
  for paths, dirctory, files in os.walk(path):
    for file in files:
        if file.endswith(extension): # eg: '.mxd'
          MapList.append(os.path.join(paths, file))
          print MapList
          for m in MapList:
                count += 1
                mxd = arcpy.mapping.MapDocument(m)
                ## --------- For each map list layers
                for lyr in arcpy.mapping.ListLayers(mxd):
                    with open("ListOfDataSources.csv", 'wb') as csvfile:
                        csvwriter = csv.writer(csvfile)
                        for dirpath, dirnames, filenames in arcpy.da.Walk(path):
                            for filename in filenames:
                                desc = arcpy.Describe(os.path.join(dirpath, filename))
                                csvwriter.writerow([desc.catalogPath, desc.name, desc.dataType])


#-------------Use below to call the function----------------#
ListMXDSources(path=r"ROOT FOLDER LOCATION",extension=".mxd")