Skip to content

Instantly share code, notes, and snippets.

@bonface221
Created July 31, 2024 10:45
Show Gist options
  • Save bonface221/e61150c9a81b1c81d80b4c6790bb1f03 to your computer and use it in GitHub Desktop.
Save bonface221/e61150c9a81b1c81d80b4c6790bb1f03 to your computer and use it in GitHub Desktop.
PYTHON images rename script
# rename all the images inside images folder into
# to sisters-on-the-outside-regional-leaders-training-day-2 + timestamp .jpj
import os
import time
import requests
# get the current working directory
path = os.getcwd()
# get the images folder
def rename_images():
images_folder = os.path.join(path, 'images')
# check if the folder exists
if os.path.exists(images_folder):
# get all the images in the folder
images = os.listdir(images_folder)
# loop through the images
for image in images:
# get the full path of the image
image_path = os.path.join(images_folder, image)
# get the timestamp
timestamp = time.time()
# rename the image
os.rename(image_path, os.path.join(
images_folder, f'sisters-on-the-outside-regional-leaders-training-day-2-{timestamp}.jpg'))
time.sleep(3)
print('Images renamed successfully')
else:
print('Images folder does not exist')
if __name__ == '__main__':
rename_images()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment