1.python修改某个目录文件名称
from pathlib import Path
p1 = Path(r"C:\Users\Administrator\Desktop\tmp\test_md")
# 给文件编号
count = 1
# 匹配所有.md结尾的文件
for file in p1.glob("*.md"):
new_file = p1 / f"{count}.{file.name}"
file.rename(new_file)
count += 1
# 还原文件名
# for file in p1.glob("*.jar"):
# file_name_list = file.name.split(".", maxsplit=2)
# new_file = p1 / f"{file_name_list[-1]}"
# file.rename(new_file)
2.python生成ipv6地址
# 方式1
ip1 = ipaddress.IPv6Address(random.randint(0, 2**128-1))
# 方式2
':'.join('{:x}'.format(random.randint(0, 2**16 - 1)) for i in range(8))
标签:count,md,p1,name,244,file,new,工具
From: https://www.cnblogs.com/liuzhanghao/p/17835862.html