How to search for .mxd that contain a specific word within its filename

Discussion created by eliz.mitt on Mar 21, 2013
Latest reply on Mar 22, 2013 by eliz.mitt

I'm fairly new to coding with Python. I have to walk through every folder and change the data source of all layers within each map document. But before doing so, I want to make a copy of each .mxd (and add the word 'Copy' to the filename) and then only apply changes to the .mxds that contain 'Copy' in the file name (in order not to alter any original .mxd files). I have successfully walked through every folder and saved a copy of every map but am stuck on how to iterate through all the .mxds that contain 'Copy' in the file name and only change the data source in those mxds.
Thanks, Elizabeth

for subdir, dirs, files in os.walk(rootfolder):
    for filename in files:
        fullPath = os.path.join(subdir, filename)
        if os.path.isfile(fullPath):
            basename, extension = os.path.splitext(fullPath)
            if extension.lower() == ".mxd":
                mxd = arcpy.mapping.MapDocument (fullPath)
                mxd.saveACopy(subdir +"\\Copy_" + filename)

                #This is where I am encountering problems with how to only apply changes to mxd's file names that contain 'Copy'              
                term = "Copy"
                if term in basename:
                    for lyr in arcpy.mapping.ListLayers(mxd):
                        if lyr.supports("DATASOURCE"):
                        # List the layer's data source
                    arcpy.AddMessage("The file is not a copy of the original")