A Python script that turns every image in a folder into a single image sequence
What is brand.0?
Imagine you have a folder on your computer filled with files. These could be anything—photos from your latest holiday, documents for work, or even a sequence of 3D renderings from your latest project. The problem? They're all over the place, named inconsistently, or perhaps there's a misspelling across multiple files that's driving you nuts. Enter Brand.0, your digital tidying companion designed to bring order to this chaos.
Here's how it works in a practical, step-by-step manner:
Surveying the Scene: Brand.0 starts by looking at the contents of a specific folder you point it to. This is the target area where the action will happen, much like deciding which room to clean first in your house.
Ignoring the Hidden Stuff: It smartly skips over any hidden files—those starting with a '.'—since they're usually not what you're looking to organize. Think of it as ignoring the stuff tucked away in drawers that doesn't need sorting.
Getting Things in Order: Before making any changes, Brand.0 sorts your files. This step ensures that any naming sequence it applies will follow the existing order, which is particularly handy if you're working with files that need to remain in a certain sequence, like a series of images or documents.
The Renaming Magic: This is where Brand.0 shines. You give it a prefix—essentially a new base name for your files—and it renames each file in the folder sequentially with that prefix, followed by a number. This could turn a messy list of files into a neatly ordered set like "Project_Doc_01," "Project_Doc_02," and so on. It’s perfect whether you're looking to organize a diverse set of files or correct a simple misspelling across a series of 3D image renders.
Keeping You in the Loop: As it works, Brand.0 will keep you updated, letting you know what changes it's making. There's no guesswork; you'll see the transformation as it happens.
Job Done: Once Brand.0 finishes, your folder will be transformed. Files that were once disorganized or incorrectly named are now in perfect order, easy to navigate, and labeled just the way you want.
Brand.0 is more than just a script; it's a tool for anyone looking to bring a level of organization to their digital files with minimal fuss. Whether you're dealing with a large collection of personal photos or need to correct a naming error across a batch of files for work, Brand.0 offers a straightforward solution to get your files in order quickly and efficiently.
INSTRUCTIONS:
Before you run your code, duplicate your folder of files (as backup).
Define your Directory Path.
Define your Prefix.
Hit run and you’re done!
You can delete your backup folder :)
The Code
import os
def rename_files_sequentially(directory, prefix):
# List all files in the directory
files = os.listdir(directory)
# Filter out hidden files
files = [f for f in files if not f.startswith('.')]
files.sort() # Sort the files to maintain any existing order, if necessary
# Initialize the starting number for the new filenames
start_number = 1
for filename in files:
# Extract the file extension from the original filename
file_extension = os.path.splitext(filename)[1]
# Create the new filename using the prefix and the current number, maintaining the file extension
new_filename = f"{prefix}_{str(start_number).zfill(2)}{file_extension}"
# Construct the full old and new file paths
old_file = os.path.join(directory, filename)
new_file = os.path.join(directory, new_filename)
# Rename the file
os.rename(old_file, new_file)
print(f"Renamed '{filename}' to '{new_filename}'")
# Increment the number for the next filename
start_number += 1
# Specify the directory containing the files and the new prefix for the filenames
directory_path = '/DIRECTORY/PATH/GOES/HERE'
prefix = 'Rename_Your_File_Here'
rename_files_sequentially(directory_path, prefix)
print("File renaming completed.")