Advertisement
here2share

# bulk_rename_crdownload.py

Feb 29th, 2024 (edited)
1,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # bulk_rename_crdownload.py
  2.  
  3. import os
  4. import tkinter
  5. from tkinter import filedialog
  6.  
  7. root = tkinter.Tk()
  8. root.withdraw() # Hide the root window
  9. folder = filedialog.askdirectory(parent=root, title="Choose a folder")
  10. files = os.listdir(folder)
  11.  
  12. for file in files:
  13.     try:
  14.         if file.endswith(".crdownload"):
  15.             new_file = file.replace(".crdownload", "")
  16.             os.rename(os.path.join(folder, file), os.path.join(folder, new_file))
  17.             print(f"Renamed {file} to {new_file}")
  18.         elif '.' in file:
  19.             new_file = file+".crdownload"
  20.             os.rename(os.path.join(folder, file), os.path.join(folder, new_file))
  21.             print(f"Renamed {file} to {new_file}")
  22.     except:
  23.         0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement