Python__递归遍历文件
http://zhangjunhd.blog.iyunv.com/113473/453857http://www.cnblogs.com/xuxm2007/archive/2010/08/09/1795504.html
http://www.cnblogs.com/phonefans/archive/2008/10/15/1311707.html
#coding=gbk
'''os.walk(dir) 是三列的数组'''
import os
dir = os.getcwd()
for cons in os.walk(dir):
print cons
#根目录、所有目录、目录下的文件
for root, dirs, files in os.walk(dir):
for name in files:
print os.path.join(root, name)
def getAllFile (dir, list):
for root, dirs, files in os.walk(dir):
for name in files:
list.append( os.path.join(root, name) )
return len(list)
file.read()读全部
file.read(N) N个字节
file.readline()
file.readlines() return a list
file.write(...)
file.seek(0)
file.next()
file.close()
#!/usr/bin/python
import os
import shutil,string
def subString(str, sub):
return sub in str
dir = '/Users/xserver/Desktop/new_res/'
for root, dirs, files in os.walk(dir):
for name in files:
path = os.path.join(root, name)
if subString(path, '.jpg'):
path2 = path.replace('.jpg','.png')
print path
shutil.move(path, path2);
页:
[1]