用python计算出大文件的md5码,某路径下所有文件的md5码
2014-11-14 10:33
330 查看
#coding:utf-8 #md5check.py #读文件,转成md5码 #如没有文件路径,则询问 #是文件,返回md5码 #是路径把其下所有文件返回md5码 #参考:http://www.joelverhagen.com/blog/2011/02/md5-hash-of-file-in-python/ import hashlib import sys import os def md5Checksum(filePath): fh = open(filePath, 'rb') m = hashlib.md5() while True: data = fh.read(8192) if not data: break m.update(data) fh.close() return m.hexdigest() def pathispath(ps_path): if os.path.isfile(ps_path): pa_path=os.path.split(ps_path) print ' '*32,pa_path[0] print md5Checksum(ps_path), print pa_path[1] else: if os.path.isdir(ps_path): for ps_one in os.walk(ps_path): print ' '*32,ps_one[0] for ps_file in ps_one[2]: print md5Checksum(os.path.join(ps_one[0],ps_file)), print ps_file if __name__ == '__main__': ls_file='' if len(sys.argv)>1: ls_file=sys.argv[1] if ''==ls_file: ls_file=raw_input('filepath?:') if os.path.exists(ls_file): #if os.path.isfile(ls_file): # print md5Checksum(ls_file) #else: # if os.path.isdir(ls_file): # pathispath(ls_file) pathispath(ls_file) else: print 'not filepath!'
相关文章推荐
- python输出指定目录下所有文件(全路径),并核对md5码
- 删除指定路径根目录所有文件-python
- 删除指定路径根目录所有文件-python
- Python获取文件夹下所有的文件路径列表
- python3 计算文件夹中所有py文件里面代码行数,注释行数,空行数
- Python计算一个目录下的所有文件的md5值,在Linux系统下面
- python 删除某个路径下所有文件及模块调用注意事项
- 编写一个Python程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径
- python 文件和目录 当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径。
- Python3爬虫之爬取某一路径的所有html文件
- Python读取路径下的所有文件
- Python遍历路径下所有文件
- python获取指定路径下所有指定后缀文件的方法
- python 扫描路径下的所有文件
- python获取指定路径下的所有文件
- Python获取指定路径下的某类型文件的所有文件名
- python获取指定路径下所有指定后缀文件的方法
- Python:遍历一个目录下所有的文件及文件夹,然后计算每个文件的字符和line的小程序
- 【Python】遍历某目录下的所有文件夹与文件的路径、输出中文乱码问题
- Python列出当前目录下所有含有指定名称的文件(包括路径)