Python批量更改文件名

Python 城市风 11/4/2024 377 次 0 条

 

import os

for root, dirs, files in os.walk(os.getcwd()):
    for filename in files:
        if filename.endswith(".mp3"):
            old_file = os.path.join(root, filename)
            new_file = os.path.join(root, filename[:-18]+filename[-4:])
            os.rename(old_file, new_file)  
            print(f"Renamed: {old_file} to {new_file}")