我是一个懒人,没办法一一文字写了,只好多截图了。
本文介绍下怎样将文件,移动到指定的文件夹。
如下图,我们将福建的每个区县批量出了一张专题地图。
具体怎么批量出图,可以查看后文的推荐。
我们现在,批量创建福建各个地级市的文件夹,将各地级市的各区县的专题图批量复制或者移动到各地级市文件夹中。
思 路
以下是代码:
# -*- coding:UTF-8 -*-import arcpyimport osimport shutilarcpy.env.workspace=r'D:\ABC.gdb'jpgPath='C:\\Users\\ygb_709\\Desktop\\A20200713'mapPath='C:\\Users\\ygb_709\\Desktop\\A20200305A'jpgPath1=jpgPath+'\\'countyList=[]cityList=[]fields=['PAC','NAME','地级市']mycursor=arcpy.da.SearchCursor('fj_xian',fields)for row in mycursor: countyList.append(row[1]) cityList.append(row[2])del mycursorfor val in set(cityList): print val filePath=jpgPath1.decode('utf-8')+val if not os.path.exists(filePath): arcpy.CreateFolder_management(jpgPath,val) print(u'成功创建文件夹:——'+filePath)listNum=len(countyList)for num in range(1,listNum+1): print(u'复制:'+countyList[num-1]) for root,dirs,files in os.walk(mapPath): for file in files: fileName=os.path.splitext(file)[0] if fileName==countyList[num-1].encode('gbk'): srcFile=os.path.join(root,file) decJpg=jpgPath1+cityList[num-1].encode('gbk')+"\\"+file shutil.copy(srcFile,decJpg) print(u'复制成功————'+countyList[num-1]+".jpg")
点击下方 阅读原文 查看完整的视频解说