Created
July 31, 2024 10:45
-
-
Save bonface221/e61150c9a81b1c81d80b4c6790bb1f03 to your computer and use it in GitHub Desktop.
PYTHON images rename script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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