Skip to content

Instantly share code, notes, and snippets.

@aliyevorkhan
Created September 9, 2020 20:23
Show Gist options
  • Save aliyevorkhan/00fff31cf9cfa46b5d6f42b0d061c009 to your computer and use it in GitHub Desktop.
Save aliyevorkhan/00fff31cf9cfa46b5d6f42b0d061c009 to your computer and use it in GitHub Desktop.
import os
import datetime
from time import sleep
for file in os.listdir(os.getcwd()):
if file.endswith('.jpg'):
os.rename(file, "img_"+datetime.datetime.now().strftime("%Y%m%d-%H%M%S%f")+'.jpg')
sleep(0.05)
@aliyevorkhan
Copy link
Author

this script is able to change image file names in current directory
for unique names I used datetime
for avoid race conditions I used sleep function in time library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment