#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-10-16 16:55:50
# @Author : M.F.Y (4021019@qq.com)
# @Link : http://4021019.org
# @Version : $Id$
import os
import hashlib
## 遍历某目录下的所有子目录及文件,
## 返回文件的
## filename 带路径
## filesize 大小
## filemd5值
## 返回文件md5值
def md5sum(filename):
fd = open(filename,"r")
fcont = fd.read()
fd.close()
fmd5 = hashlib.md5(fcont)
return fmd5.hexdigest()
## 遍历文件夹,将文件信息写入文件
def write2file(rootdir):
import os
_files = []
list = os.listdir(rootdir)
for i in range(0,len(list)):
path = os.path.join(rootdir,list[i])
if os.path.isdir(path):
_files.extend(write2file(path))
if os.path.isfile(path):
myfiles = open("file_list.txt","a+")
myfiles.writelines(path + ',' + str(os.path.getsize(path)) + ',' + md5sum(path)+'\n')
myfiles.close()
_files.append(path)
return _files
吃面条
网友评论