TAGS :Viewed: 8 - Published at: a few seconds ago

[ variable is not defined, but it is defined as global variable, python ]

I keep getting the error name 'copyDir is not defined but it is defined as a global variable in my code. What is wrong? I reviewed some of the other posts here similar to this but still can't understand the problem. Here's the beginning part of my code:

import arcpy, os, shutil, re
mapIndex = r'C:\Temp\temp.gdb\MapSets_All'
copydDir = r'D:\MapSheetImages\All_Images'

fields = ['FileSpecDir','is_name']

for row in arcpy.da.SearchCursor(mapIndex,fields):
    arcpy.env.workspace = row[0]
    rstrList = arcpy.ListRasters()

    for dir, folders, files in os.walk(row[0]):
            if 'CCS27z2e' in folders:
                for r in rstrList:
                    if row[1] in r:
                        rOrigPath = os.path.join(row[0],r)
                        rNewPath = os.path.join(copyDir,r)
                        if not os.path.isfile(rNewPath):
                            arcpy.AddMessage('now copying '+r)
        except Exception as e:
            print e

Answer 1

You have a typo:

copydDir = r'D:\MapSheetImages\All_Images'

should be:

copyDir = r'D:\MapSheetImages\All_Images'