Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions Bulk_Image_Renamer_#689/README.md
Original file line number Diff line number Diff line change
@@ -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.

---


65 changes: 65 additions & 0 deletions Bulk_Image_Renamer_#689/RenameImageFileNamesInAFolder.py
Original file line number Diff line number Diff line change
@@ -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:

<prefix>_1.<ext>, <prefix>_2.<ext>, <prefix>_3.<ext>, ...

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)