Skip to content
Merged
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
15 changes: 15 additions & 0 deletions Bulk File Renamer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Bulk File Renamer

A simple Python script that allows you to rename multiple files in a directory based on a specified pattern. This script is useful for organizing and managing large collections of files, such as photos, documents, or music.

## How to use

1. Clone the repository or download the `main.py` script.
2. Open a terminal and navigate to the directory where the script is located.
3. Run the script using the following command:

```bash
python main.py
```

4. Follow the onscreen prompts.
22 changes: 22 additions & 0 deletions Bulk File Renamer/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Bulk File Renamer
A simple script to bulk rename files in a directory by adding a base filename as a prefix."""
import os

def main():
"""Main function to execute the bulk file renaming process."""
rootdir = input("Input directory to iterate through. \
Leave blank for current working directory: ")
if not rootdir:
rootdir = os.getcwd()
print(f"{rootdir} selected")

base_filename = input("Input base file name to use for renaming: \
Leaving blank will result in an underscore being used as the prefix: ")

for root, _, files in os.walk(rootdir):
for file in files:
print(file)
print(f"{file} renamed to {(base_filename + '' if not base_filename else '_') + file}")
os.rename(os.path.join(root, file), \
os.path.join(root, (base_filename + "" if not base_filename else "_") + file))
main()
Loading