python统计两文件夹下文件的名字一样获取不一样的文件名

#!/usr/local/bin/python
#-*- coding: utf-8 -*-
import os
import time
import datetime
def time_differ(date1,date2):
    date1 = datetime.datetime.strptime(date1,"%H:%M:%S")
date2 = datetime.datetime.strptime(date2,"%H:%M:%S")
if date1 < date2:
    return date2 - date1
else:
    return date1 - date2

def file_name(file_dir):
    L=[]
    for root,dirs,files in os.walk(file_dir):
        for file in files:
            if os.path.splitext(file)[1] == '.jpg':
                L.append(os.path.join(root,file.strip(".jpg")).split("/")[-1])
    return L
starttime = time.strftime('%H:%M:%S',time.localtime(time.time()));
print "开始时间",starttime




list_small = file_name("/small")
print "小图的个数",len(list_small)


list_big = file_name("/sipa_big_picture")
print "大图的个数",len(list_big)
print "大图小图一共相差",(len(list_small)-len(list_big))
res_list = list(set(list_small).difference(set(list_big)))


for item in res_list:
    file = open("/home/test_data.txt","a+")
    file.write(str(item+"\n"))
    file.close()
endtime = time.strftime('%H:%M:%S',time.localtime(time.time()))
print "写入文本结束时间",endtime


totaltime = time_differ(starttime,endtime)
print "总共用时",totaltime

你可能感兴趣的:(python)