python生成哈希目录
来源:互联网 发布:淘宝售前客服术语大全 编辑:程序博客网 时间:2024/05/16 14:47
c++代码获取一个字符串的md5值并输出
#include "md5.h"#include <string>#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;extern "C"{ void getStrMd5(char* filePath) { MD5 md5(filePath); std::string str = md5.md5(); printf("%s", str.c_str()); }}
生成动态库,供python调用
g++ md5.cpp getStringMd5.cpp -fPIC -shared -o getHash.so
获取字符串的md5值:getHashValue.py
#!/usr/bin/pythonfrom ctypes import *import os import systarget = (sys.argv)[1]libtest = cdll.LoadLibrary(os.getcwd() + '/getHash.so') print libtest.getStrMd5(target)
处理得到哈希目录脚本:process.py
32位md5值,前4位用作目录名, 后28位用作文件名
#!/usr/bin/pythonimport sysimport osimport os.pathimport shutilimport commandssrcPath = os.path.join((sys.path)[0], "res")desPath = os.path.join((sys.path)[0], "HashRes")if os.path.exists(desPath): shutil.rmtree(desPath)os.mkdir(desPath)def process(path): for parent, dirnames, filenames in os.walk(path): for file in filenames : if file != ".DS_Store" : fullPath = parent + "/" + file splitPath = fullPath[len(path)+1:] command = "python getHashValue.py " + splitPath f = os.popen(command) data = f.readlines()[0][0:31] fileNewPath = desPath + "/" + data[0:4] if not os.path.exists(fileNewPath): os.mkdir(fileNewPath) shutil.copyfile(parent+"/"+file, fileNewPath+"/"+data[4:32])process(os.path.join((sys.path)[0], "res"))
1 0
- python生成哈希目录
- python 生成目录树
- 用Python生成目录树
- python 实现生成目录树及显示文件大小
- python读取目录下文件并生成日志
- 生成目录结构算法的bash, perl和python实现
- python 生成目录树及显示文件大小的代码
- python之生成文件/目录的md5值
- 组合模式(python版) 兼有 目录结构(多叉树的生成)
- python目录
- 目录树生成
- word 如何生成目录!
- Word生成目录
- 如何生成目录树
- WORD自动生成目录
- Excel自动生成目录
- word 2007 目录生成
- Excel自动生成目录
- android常用控件ViewPager(一) ViewPager基本应用
- Java Socket图片文件传输
- poj1064(二分处理浮点类型技巧)
- linux上使用netstat查看当前服务和监听端口
- java中IO流的操作
- python生成哈希目录
- 第九周 OJ-2
- 入门训练 序列求和
- NOIP模拟题[递推][并查集][DP]
- 要循序渐进的学,最好现学现用
- Rxjava(过滤类)-Debounce
- Mybatis自定义typehandler
- SQLite3命令
- Day49:Before going to XiaMen