需求:经常从一些视频app或应用取出一些视频 图片,它们总是喜欢把文件名后缀改没了。然后很多这种类似问题,一次次手动重命名很烦。那么我们就用python来搞定它
code:
import os
f = "D:\\video\\uil-video\\"
files = os.listdir(f)
#print (files)
for file in files:
#print (file)
os.rename(os.path.join(f + file ), os.path.join(f + file + ".mp4" ) )
然后大功告成!
如果是加前缀
import os
path = 'D:\\video\\uil-images\\'
files = os.listdir(path)
for file in files:
NewName = os.path.join(path, "Lee_"+file)
OldName = os.path.join(path, file)
os.rename(OldName, NewName)