python 脚本编写

最近在百度云上下载的东西后面有些莫名其妙的东西。如:xxx.baiduyun.downloading。这样一来给我们造成无法打开的窘境,为了避免需要删除后缀名。本着懒人的精神编写代码删除后缀名。

代码:

import re
import os
path = r'C:python36jikePython'
files = os.listdir(path)

for file in files:
if (re.search(r".baiduyun.p.downloading",file)):
newname = re.sub(r".baiduyun.p.downloading","",file)
os.rename(os.path.join(path,file),os.path.join(path,newname))

代码前

代码后

原文地址:https://www.cnblogs.com/hnsya/p/10064422.html