您的位置:首页 > 编程语言 > Python开发

Python 遍历文件查找不同

2015-08-30 02:11 621 查看
<span style="font-size:18px;">import os

arr1 = []
path = '.\\'
def fun(dir,arr):
i = 0
j = 0
for t in os.listdir(dir):
t1 = os.path.join(dir,t)
if os.path.isfile(t1):
arr.append((t,t1))
elif os.path.isdir(t1):
fun(t1,arr)
f = open('.\\result.txt','w')
fun(path,arr1)
arr1.sort()
for i in range(0,len(arr1)-1):
if arr1[i][0] != os.path.basename(__file__) and arr1[i][0] != 'result.txt':
print('{0:-<50}'.format(arr1[i][0]),arr1[i][1],file = f)
f.close()
print('over!')</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: