python遍历文件目录
在一般情况下的遍历
# -*- coding: utf-8 -*-
import os
import os.path
rootdir = "D:\Music".decode('utf-8')#指明被遍历的文件夹
for parent, dirnames, filenames in os.walk(rootdir):#三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字
for dirname in dirnames:#输出文件夹信息
print "parent is:" + parent
print "dirname is" + dirname
for filename in filenames:#输出文件信息
print "parent is:" + parent
print "filename is:" + filename
print "the full name of the file is:" + os.path.join(parent, filename)#输出文件路径信息
在arcpy中的遍历栅格数据:
# -*- coding: utf-8 -*-
import arcpy
arcpy.env.workspace = "C:\Users\Administrator.2013-20151214GI\Desktop\眉山DEM测试\眉山DEM测试\mydemtest.mdb".decode('utf-8')
ds = arcpy.ListDatasets()
dsCount = len(ds)
for dataset in ds:
print dataset
print dsCount
print(ds)
转载自:https://blog.csdn.net/xiongxiongdeBear/article/details/50972790