我不断收到错误name 'copyDir is not defined
,但它在我的代码中定义为全局变量。怎么了?我在这里回顾了一些类似的其他帖子,但仍然无法理解这个问题。这是我的代码的开头部分:
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)
答案 0 :(得分:1)
你有一个错字:
copydDir = r'D:\MapSheetImages\All_Images'
应该是:
copyDir = r'D:\MapSheetImages\All_Images'