python os 移动文件_基于GIS的Python应用:批量移动文件到指定文件夹中

我是一个懒人,没办法一一文字写了,只好多截图了。

本文介绍下怎样将文件,移动到指定的文件夹。

如下图,我们将福建的每个区县批量出了一张专题地图。

具体怎么批量出图,可以查看后文的推荐。

7740d261beeadcc1bbc3b9638d1b7434.png

我们现在,批量创建福建各个地级市的文件夹,将各地级市的各区县的专题图批量复制或者移动到各地级市文件夹中。

dc3f032c42992f0e09d60d684b368546.png

思   路

53fa082e42b8f90b81bb124388c36e2d.png

以下是代码:

# -*- 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")           

点击下方   阅读原文  查看完整的视频解说

04d16eee8fa4641c8486895ce7692efa.png

240e456cbe13429873176203fca89624.png

98de9324747369c5b58f5432dcc72a28.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值