folderPath = 'C:\temp' targetDataSource = 'C:\mapping\shapefile.shp' files = os.listdir(folderPath) for curFile in files: if curFile.endswith(".txt"): for lyr in arcpy.mapping.ListLayers(curFile): if lyr.dataSource == targetDataSource: print("Outdated layer found at " + lyr.lyr_file_path)