''' NAME: Batch Image Renaming Tool (BIRT) VERSION: 1.1.4 DESCRIPTION: Used to bulk rename files in a uniform, randomized way AUTHOR: Justus Fee CREATED: 16 April 2019 LAST UPDATED: 18 May 2021 TODO: Multithread ''' import os import time import uuid ''' Generates a unique hex ID. ''' def generate_filename(): return uuid.uuid4().hex; ''' Counts the number of files that are going to be modified. For use with progress display. ''' def count_files(folder): count = 0 for (root, dirs, files) in os.walk(folder, topdown=True): for pic in files: count += 1 return count ''' Where the magic happens. ''' def main(): print("---[ Welcome to Justus' Batch Image Renaming Tool (BIRT). ]---") folder = input("Please enter directory path: \n>") while not os.path.isdir(folder): print("[!] Invalid directory. Try again.") folder = input("Please enter directory path: \n>") print("Validating directory...") total = count_files(folder) user_choice = input("Directory validated. Run script? (Y/N)\n>") if user_choice.lower() == "y": print("") pic_count = 0 start_time = time.time() for (root, dirs, files) in os.walk(folder, topdown=True): for pic in files: # Get file extension extension = os.path.splitext(pic)[1] # Generate new filename new_filename = generate_filename() + extension # Rename file os.rename(os.path.join(root, pic), os.path.join(root, new_filename)) # Update status print("[{:.2%}] Processing file {:,} / {:,}".format(((pic_count+1) / total), pic_count+1, total), end="\r") pic_count += 1 print("\n\nJob's done!") print("{:<20} {:,}".format("Files processed:", pic_count)) print("{:<20} {:.2} minutes".format("Time elapsed:", (time.time() - start_time) / 60)) else: print("Script aborted. Have a nice day.") input("\nPlease press ENTER to quit.") ''' Typical Python stuff. ''' if __name__ == "__main__": main()