Untitled

 avatar
unknown
plain_text
9 months ago
843 B
1
Indexable
import os

# Source directory containing the .jpg files
src_dir = 'source_directory'

# Destination directory to save the renamed .jpg files
dst_dir = 'destination_directory'

# Create the destination directory if it doesn't exist
if not os.path.exists(dst_dir):
    os.makedirs(dst_dir)

# Initialize a counter for the file names
counter = 1

# Iterate through all the .jpg files in the source directory
for filename in os.listdir(src_dir):
    if filename.endswith('.jpg'):
        # Construct the full file path
        src_file = os.path.join(src_dir, filename)

        # Construct the destination file path with the numbered format
        dst_file = os.path.join(dst_dir, f'{counter}.jpg')

        # Rename the file
        os.rename(src_file, dst_file)

        # Increment the counter
        counter += 1
Editor is loading...
Leave a Comment