0

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)
5
  • 2
    Your variable is copydDir, not copyDir. A typo - copyDir is not defined. Commented Jan 15, 2015 at 14:45
  • the code is very long with the except statement at the end so i didn't post it all, i'll add that part it Commented Jan 15, 2015 at 14:45
  • 2
    @AndrewDunai oh wow I could not see that thanks!! Commented Jan 15, 2015 at 14:49
  • @AndrewDunai It would be apt if you post it as an answer, instead of others Commented Jan 15, 2015 at 14:50
  • @BhargavRao Lawrence already did it, so let it be him :) Commented Jan 15, 2015 at 14:52

1 Answer 1

1

You have a typo:

copydDir = r'D:\MapSheetImages\All_Images'

should be:

copyDir = r'D:\MapSheetImages\All_Images'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.