最近整理数据集发现命名全是新建……,想着给每个文件重命名个独一无二的名字
重命名前: 重命名后:
代码:
在需要批量处理的文件夹中创建一个.py文件,把代码复制过去,然后把路径改成当前文件夹即可
import hashlib
import os
# 待加密信息
def md5(str):
# 创建md5对象
m = hashlib.md5()
b = str.encode(encoding="UTF-8")
m.update(b)
return m.hexdigest()[8:-8].lower() # 16/32位、大小写在这里修改
entries = os.listdir(r"E:\***\******") # 遍历文件夹中的文件
for entry in entries:
if entry.endswith(".txt"):
print(entry)
with open(entry,"r",encoding='utf-8') as fo:
text = fo.read()