More

Search MXDs with specific dataSource layer using Python

Search MXDs with specific dataSource layer using Python


I work with ArcGIS 10.3 and I try to search a specific layer (with dataSource named "D:desktopProjectlayers1.jpg">


From the listfiles docs:

Returns a list of files in the current workspace based on a query string

So mxdname does not have a pathway attribute. It's simply a string of the mxd name.


Finally, i used this code:

import arcpy from arcpy import mapping as m from os import path, walk root_directory = r"D:PROJECTS" path_to_find = r"F:GIS	opo_5000050000.sid" def FindMaps(root_directory, path_to_find): maps = [] for root, dirnames, filenames in walk(root_directory): for fname in [f for f in filenames if f.endswith(".mxd")]: mxdPath = path.join(root, fname) if not path.isfile(mxdPath): continue mxd = m.MapDocument(mxdPath) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] for df in m.ListDataFrames(mxd): for lyr in m.ListLayers(mxd, data_frame=df): if lyr.supports("DATASOURCE"): if lyr.dataSource == path_to_find: print(mxdPath) maps.append(mxdPath) break return maps FindMaps(root_directory, path_to_find)

Watch the video: PYTHON - ΜΑΘΗΜΑ 20 - ΤΕΚΜΗΡΙΩΣΗ ΚΑΙ ΕΛΕΓΧΟΣ - Μέρος 3 από 6 - Έλεγχος Συνάρτησης