1. import os
    2. def GetDirFiles(dir, keyWord):
    3. for home, dirs, files in os.walk(dir):
    4. for dir in dirs:
    5. print(dir)
    6. for filename in files:
    7. nameOrigin = os.path.join(home, filename)
    8. nameNew = os.path.join(home, filename.replace(keyWord, ''))
    9. print(nameOrigin)
    10. print(nameNew)
    11. os.rename(nameOrigin, nameNew)
    12. if __name__ == "__main__":
    13. GetDirFiles("C:\\Users\\Administrator\\Desktop\\路径", "要删除的字")