From 810f2258a7caa759e11cbf01c62647da52de70e6 Mon Sep 17 00:00:00 2001 From: Deepakraghavan01 <57013229+Deepakraghavan01@users.noreply.github.com> Date: Fri, 31 Oct 2025 01:04:01 +0530 Subject: [PATCH 1/2] Added script renames all image files in a specified folder sequentially --- .../RenameImageFileNamesInAFolder.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Bulk_Image_Renamer_#689/RenameImageFileNamesInAFolder.py diff --git a/Bulk_Image_Renamer_#689/RenameImageFileNamesInAFolder.py b/Bulk_Image_Renamer_#689/RenameImageFileNamesInAFolder.py new file mode 100644 index 0000000..ef9d1d8 --- /dev/null +++ b/Bulk_Image_Renamer_#689/RenameImageFileNamesInAFolder.py @@ -0,0 +1,65 @@ +""" +This script renames all image files in a specified folder sequentially +with a user-defined prefix. The renamed files will follow the format: + + _1., _2., _3., ... + +For example, if the prefix is 'photo' and the folder contains: + imgA.jpg, imgB.png, imgC.jpeg + +After running the script, the files will be renamed as: + photo_1.jpg, photo_2.png, photo_3.jpeg + +Supported image extensions: .jpg, .jpeg, .png, .gif, .bmp, .tiff +""" + +import os + +def rename_images_in_folder(folder_path: str, prefix: str) -> None: + """ + Rename all image files in a given folder sequentially with a user-defined prefix. + + Args: + folder_path (str): The path to the folder containing the images. + prefix (str): The prefix to use for renamed images. + + Returns: + None + """ + # Supported image file extensions + image_extensions = ('.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff') + + # Validate folder path + if not os.path.isdir(folder_path): + print(f"Error: '{folder_path}' is not a valid directory.") + return + + # Get a list of image files in the folder + images = [f for f in os.listdir(folder_path) if f.lower().endswith(image_extensions)] + images.sort() # Sort alphabetically for consistent renaming order + + if not images: + print("No image files found in the specified folder.") + return + + # Rename images sequentially + for index, filename in enumerate(images, start=1): + old_path = os.path.join(folder_path, filename) + extension = os.path.splitext(filename)[1] + new_filename = f"{prefix}_{index}{extension}" + new_path = os.path.join(folder_path, new_filename) + + try: + os.rename(old_path, new_path) + print(f"Renamed: {filename} → {new_filename}") + except Exception as e: + print(f"Error renaming {filename}: {e}") + + print("\nRenaming completed successfully!") + + +if __name__ == "__main__": + # Example usage: User provides folder path and prefix + folder = input("Enter the folder path containing images: ").strip() + prefix = input("Enter the prefix for renamed images: ").strip() + rename_images_in_folder(folder, prefix) From c6c5f73d77233fb991f3bafba8b8f579d3f05789 Mon Sep 17 00:00:00 2001 From: Deepakraghavan01 <57013229+Deepakraghavan01@users.noreply.github.com> Date: Fri, 31 Oct 2025 01:09:22 +0530 Subject: [PATCH 2/2] Add README for Image Renamer Script Added README.md for the image renamer script detailing features, usage, and supported formats. --- Bulk_Image_Renamer_#689/README.md | 108 ++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Bulk_Image_Renamer_#689/README.md diff --git a/Bulk_Image_Renamer_#689/README.md b/Bulk_Image_Renamer_#689/README.md new file mode 100644 index 0000000..e6eb648 --- /dev/null +++ b/Bulk_Image_Renamer_#689/README.md @@ -0,0 +1,108 @@ + +# Image Renamer Script + +> A lightweight Python utility to rename all images in a folder sequentially with a custom prefix. + +--- + +## Features + +* **Automatic renaming** of all image files in a folder +* **Custom prefix support** (e.g., `photo_1.jpg`, `photo_2.png`, etc.) +* **Preserves file extensions** correctly +* **Alphabetical renaming order** for predictable results +* **No external dependencies** — just pure Python +* Works on **Windows**, **macOS**, and **Linux** + +--- + +## Example + +### Before: + +``` +imgA.jpg +imgB.png +imgC.jpeg +``` + +### After running with prefix `photo`: + +``` +photo_1.jpg +photo_2.png +photo_3.jpeg +``` + +--- + +## 🧠 Usage + +### 1. Clone or Download the Script + +Download the file **`rename_images.py`** to your computer. + +### 2. Run the Script + +In your terminal or command prompt, navigate to the script’s folder and run: + +```bash +python rename_images.py +``` + +### 3. Provide Input + +You’ll be prompted to enter: + +1. The **folder path** containing your images +2. The **prefix** for renamed files + +Example session: + +``` +Enter the folder path containing images: /Users/deepak/Pictures/Vacation +Enter the prefix for renamed images: beach +``` + +Output: + +``` +Renamed: imgA.jpg → beach_1.jpg +Renamed: imgB.png → beach_2.png +Renamed: imgC.jpeg → beach_3.jpeg + +Renaming completed successfully! +``` + +--- + +## Supported Image Formats + +| Extension | Type | +| --------- | --------------------------- | +| `.jpg` | JPEG image | +| `.jpeg` | JPEG image | +| `.png` | Portable Network Graphic | +| `.gif` | Graphics Interchange Format | +| `.bmp` | Bitmap | +| `.tiff` | Tagged Image File Format | + +--- + +## Notes & Tips + +* The script **renames files in-place**, so make a **backup** if needed. +* Files are renamed **alphabetically** (not by creation date). +* Ensure you have **write permissions** in the target directory. +* Non-image files are **ignored** safely. + +--- + +## Requirements + +* **Python 3.6+** +* No third-party libraries required — uses the built-in `os` module. + +--- + +