ArcGIS & python学习:(一)批处理修改文件名(NDVI数据)
2014-10-22 17:13
405 查看
下载的NDVI数据,一共26年,每年有24个文件夹(每月2个),每个文件夹下3个文件,文件名很长,类似这样的:“Subset_China_EA85aug15b.n09-VIg_albers_TIFF.tif”,看着太累,而且之后处理需要每年的放在一个文件夹下,批量修改文件名容易出错且累死,用python很快可以做到。
折腾了1天,总算倒腾出来了,先记录一下(环境:ArcGIS10.0,python2.6):
修改后,文件名缩短了,看着舒服多了。
下一步,再研究拷贝文件,把每年24个半月文件放在一个目录下,然后批量实现ArcGIS下的MVC最大合成,裁剪等。
折腾了1天,总算倒腾出来了,先记录一下(环境:ArcGIS10.0,python2.6):
# -*- coding: cp936 -*- import os.path from os.path import join, getsize print "----------------------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最大合成,裁剪等。
相关文章推荐
- Python & 数据分析学习笔记[第1篇]
- 资源&教程 | Python数据分析,详细的学习路径
- Python & 数据分析学习笔记[第2篇]
- Python3学习(一)-基础、数据类型、变量、字符串和编码、list&tuple、if、for、while、dict、set、函数与参数
- Python快速学习02:基本数据类型 & 序列
- Python学习之数据类型&(二)
- WPF学习日志1---DataGrid绑定与修改更新(数据List & 数据库)[部分代码有摘录其他文章]
- 2014年4月1日MySQL学习记录--mysql数据类型及占用空间&&修改表的语法
- Python快速学习02:基本数据类型 & 序列
- Jim's游戏外挂学习笔记4——查找怪数据数组的内存分布和地址
- 【T-MAC学习笔记10之--数据修改之插入数据,更新数据,删除数据】
- python 核心编程学习笔记(第3章) 对应Let's-python视频第4集
- arcgis python 数据更新
- [转]十天学习PHP之第六天(PHP)----学会添加删除修改数据 (2009-11-25 14:26)
- Python学习笔记七(File&Open)
- ADO.NET的数据提供程序和数据连接——ADO.NET学习&应用笔记之二
- 通过实例学习Virtools脚本语言VSL - 检索和修改数组的数据
- 通过实例学习Virtools脚本语言VSL - 检索和修改数组的数据
- Python学习笔记一:数据类型转换
- MySQL入门学习(六)修改、备份、批处理