import os i=1 for file in os.listdir("."): os.rename(file,"img"+str(i)+".bmp") i=i+1
PS: windows 防火墙会阻止脚本文件更改文件名,所以要关闭
查找文档内容
1 2 3 4 5 6 7
import os target = input("please input the search word:") for filename in os.listdir("."): if"."in filename: with open (filename,'r',encoding='UTF-8') as f: if target in f.read(): print(os.path.basename(filename))