2

I work with ArcGIS 10.3 and I try to search a specific layer (with dataSource named "D:\desktop\Project\layers1円.jpg" ) in hundred of mxd's that spread in folder "D:\PROJECTS" and it divided to hundred of sub folders, using python 2.7.8:

import arcpy,os,sys
import arcpy.mapping
from arcpy import env
env.workspace = r"D:\PROJECTS"
for mxdname in arcpy.ListFiles("*.mxd"): 
 mxd = arcpy.mapping.MapDocument(r"D:\desktop\Project\\" + mxdname)
 dfList = arcpy.mapping.ListDataFrames(mxd, "*")
 for df in dfList:
 for lyr in arcpy.mapping.ListLayers(mxd, "", df):
 if lyr.isGroupLayer == True: continue 
 if lyr.dataSource == r"D:\desktop\Project\layers1円.jpg":
 print mxdname, mxdname.pathway
 mxd.save()
del mxd

Finally, I want that python will print all the mxd's source name that contain the specific layer I search for. When I run the code I get error:

project1.mxd
Traceback (most recent call last):
 File "C:\Users\yaron.KAYAMOT\Desktop\idle.pyw", line 13, in <module>
 print mxdname, mxdname.pathway
AttributeError: 'unicode' object has no attribute 'pathway'
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Dec 20, 2015 at 12:36

2 Answers 2

2

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.

Andre Silva
10.5k12 gold badges57 silver badges109 bronze badges
answered Dec 20, 2015 at 12:57
1

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\topo_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)
answered Dec 22, 2015 at 7:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.