import os
def GetDirFiles(dir, keyWord):
for home, dirs, files in os.walk(dir):
for dir in dirs:
print(dir)
for filename in files:
nameOrigin = os.path.join(home, filename)
nameNew = os.path.join(home, filename.replace(keyWord, ''))
print(nameOrigin)
print(nameNew)
os.rename(nameOrigin, nameNew)
if __name__ == "__main__":
GetDirFiles("C:\\Users\\Administrator\\Desktop\\路径", "要删除的字")