1. 程式人生 > >python統計兩資料夾下檔案的名字一樣獲取不一樣的檔名

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