KLD
KLD

Reputation: 15

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]):
        try:
            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)
                            shutil.copyfile(rOrigPath,rNewPath)
        except Exception as e:
            print e
            arcpy.AddMessage(e)

Upvotes: 0

Views: 439

Answers (1)

Lawrence Aiello
Lawrence Aiello

Reputation: 4638

You have a typo:

copydDir = r'D:\MapSheetImages\All_Images'

should be:

copyDir = r'D:\MapSheetImages\All_Images'

Upvotes: 1

Related Questions