How do I loop a folder of mxds

14746
43
05-10-2016 08:23 AM
DevinUnderwood2
Occasional Contributor

I want to loop many mxds within a folder to retrieve layer,connection,etc. information using python.

I just need the syntax for looping through the mxds.

0 Kudos
43 Replies
JenniferMcCall4
Occasional Contributor III

You can use the Walk function in python that Michael had mentioned to loop throught the mxds.  For each mxd, you can use what he later suggested with looping through the dataframes and layers.

A loop within a loop.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Rebecca Strauch, GISP​ produced this Python addin for data inventory and “broken-link” repair.

which does project inventory, if it doesn't serve purposes, perhaps she might have some commentary on what you are trying to accomplish

RebeccaStrauch__GISP
MVP Emeritus

Devin, it definitly is worth trying my data inventory addin, as Dan mentioned.  since there are so many different types of data and data connections that can be within any mxd, there are many tests that need to be filtered thru to find the right pe.  The add in does that fairly well, but still may not catch ALL oes yet.  But it does spit out an excel and .csv output so you can see what you have.  It will do recursive mxds in a folder, and runs fairly fast so, the inventory part you should try.

if it doesn't get what you need, and .addin is just a zip file....change the extension and unzip.  You'll see how I looped thru everything, and you can grab snippets from thatand modify if needed.

DevinUnderwood2
Occasional Contributor

This looks great, I just browsed it quickly. Good advice use on a non-working testing folder/files. I will test this out. Thank you.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Keep in mind, if I remember correctly, the inventory lists all whether broken link or not. 

The broken link list will list only those, and may differ depending on relative relationship, and user permissions, if you copy the data.....which I still recommend for testing.  I'm using it to find where users have local data for mxd's that are shared and in a network drive.  helps me find the local data that needs to be centrally located and fixed.  That might not be your need....but just a tidbit of possible usage.

0 Kudos
DevinUnderwood2
Occasional Contributor

Interesting, I used Select folder to walk thru & List all types of feature classes. It writes to excel with  just title headings.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Are you saying all three output files end up blank?  I just downloaded and ran it (second button...first only shows databases, not mxd data)  against a folder  that I created in the last few days (i.e., not the computer or folder I created and tested the addin on originally) I had two mxd it, and all three files were populated. For example, the .txt file showed...

Maybe the excel file is a different version?  Maybe try double clicking the .csv and have it open in your versions of excel?

0 Kudos
DevinUnderwood2
Occasional Contributor

Yes, all outputs were blank. I opened the csv and it is blank also.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

You may want to change the .addin file to .zip, expand it and try running thru the toolbox instead as an addin with the buttons.  That way you can see a bit more of what it is trying to do.  Not sure why it is coming out blank, unless it is one of the types I dont have come red yet.  I think I have a lot of notes in the .py script itself on what does and doesn't  work. 

0 Kudos
DevinUnderwood2
Occasional Contributor

I went ahead and did as you suggested. I opened and parsed the syntax to attempt in getting only what I need. No luck in successfully creating a script for what I want. I apologize for taking up your time. You have been more than helpful. I don't know what I cant seem to get this right to loop all mxds.

0 Kudos