ArcGIS & python学习:(一)批处理修改文件名(NDVI数据)
来源:互联网 发布:工作流软件 编辑:程序博客网 时间:2024/05/23 18:34
下载的NDVI数据,一共26年,每年有24个文件夹(每月2个),每个文件夹下3个文件,文件名很长,类似这样的:“Subset_China_EA85aug15b.n09-VIg_albers_TIFF.tif”,看着太累,而且之后处理需要每年的放在一个文件夹下,批量修改文件名容易出错且累死,用python很快可以做到。
折腾了1天,总算倒腾出来了,先记录一下(环境:ArcGIS10.0,python2.6):
# -*- coding: cp936 -*-import os.pathfrom os.path import join, getsizeprint "----------------------Rename Begin--------------------------"srcdir = "F://other//pythontest//2006"for root, dirs, files in os.walk(srcdir): for file in files: #文件名(除去后缀名) filename = os.path.splitext(file)[0][0:] #后缀名 sufix = os.path.splitext(file)[1] #获取年份、月份、上或下月ab year = filename[15:-26] month = filename[17:-23] updownmonth = filename[22:-20] #print "year is ", year #print "month is ", month #print "updownmonth is ", updownmonth if month == "jan": newmonth = "01" elif month == "feb": newmonth = "02" elif month == "mar": newmonth = "03" elif month == "apr": newmonth = "04" elif month == "may": newmonth = "05" elif month == "jun": newmonth = "06" elif month == "jul": newmonth = "07" elif month == "aug": newmonth = "08" elif month == "sep": newmonth = "09" elif month == "oct": newmonth = "10" elif month == "nov": newmonth = "11" elif month == "dec": newmonth = "12" else: print "*****未找到当前月份*******" #新的名称 tempname = year + newmonth + updownmonth destfile = srcdir +"//"+ tempname +sufix file = os.path.join(srcdir,file); print "destfile is ",destfile #print "file is ",file #更改名称 os.rename(file, destfile) print "-----------------------end----------------------------"
修改后,文件名缩短了,看着舒服多了。
下一步,再研究拷贝文件,把每年24个半月文件放在一个目录下,然后批量实现ArcGIS下的MVC最大合成,裁剪等。
0 0
- ArcGIS & python学习:(一)批处理修改文件名(NDVI数据)
- 批处理学习(一)
- ArcGIS Python实现Modis NDVI批量化月最大合成
- ArcGIS Python实现Modis NDVI批量求年最大值
- windows 批处理修改文件名
- 批处理修改文件名
- 批处理修改文件名
- ArcGIS学习(一)初识ArcGIS
- ArcGIS学习(一)初识ArcGIS
- 归一化植被指数(NDVI)
- python之学习类:python修改文件名
- ArcGIS Geoprocessing 数据批处理
- 批量修改文件名-批处理应用
- Windows下批处理修改文件名
- # Python数据分析学习笔记(一)
- Python数据分析学习笔记(一)
- Python数据分析学习笔记(一)
- SpringBatch批处理框架学习笔记(一)
- [LeetCode] ZigZag Conversion
- 揭开电商零门槛创业的奥秘
- 基于ASP.NET技术将数据库中坐标点数据呈现到GOOGLE地图上 (google map开发高级篇)
- 设置背景图片不随浏览器放大而改变(背景固定,只上层div滚动)
- MySQL JDBC的queryTimeout的一个坑
- ArcGIS & python学习:(一)批处理修改文件名(NDVI数据)
- ALSA声卡驱动四之Control设备的创建
- Learning English From Android Source Code:2 Ampersand
- 网络协议端口号说明
- 深入理解Oracle 12c数据库管理 笔记
- 精简后的build.xml——只为打WAR包
- Android之Sensor 使用方法
- hdu 5013 优化疑问+dp
- 杭电acm1002A + B Problem II