I have an MXD as a template and about 650 folders. Each folder corresponds to a species.
What I want to do is to make an MXD (same as the template) in every folder of each species.
How to do this programmatically?
I have an MXD as a template and about 650 folders. Each folder corresponds to a species.
What I want to do is to make an MXD (same as the template) in every folder of each species.
How to do this programmatically?
This is just a pure Python solution. It assumes all your folders are within a root directory, and simply copies a specified MXD into each folder.
import os
import shutil
#change path to the MXD you'd like to copy
mxd_to_copy = "C:\\Projects\\Map.mxd"
#change to the root of where all the folders are stored
workspace = "C:\\Projects"
for dirpath, dirnames, filenames in os.walk(workspace):
for folder in dirnames:
if "gdb" not in folder:
output_folder = os.path.join(dirpath, folder)
shutil.copy2(mxd_to_copy, output_folder)
It'd probably be a good idea to put print output_folder in place of shutil.copy2(mxd_to_copy, output_folder) the first time to see where all the MXD will be copied.
Otherwise, I believe the only way to actually create a new MXD is through ArcObjects.
I am assuming that those folders contain data and you want to create Mxd in each one, such that the mxd will be specific to the folder that contains it. Do all the folders contain the same structure of data? Thank you!
– Bogdan Mircea Stanciu Aug 17 '15 at 15:27