Skip to content

Instantly share code, notes, and snippets.

@behroozam
Created July 27, 2019 07:20
Show Gist options
  • Save behroozam/8b8b4c1766eccf23e2932d2770863efc to your computer and use it in GitHub Desktop.
Save behroozam/8b8b4c1766eccf23e2932d2770863efc to your computer and use it in GitHub Desktop.
rename by CSV
#!/usr/bin/env python3
import os
import csv
# Coded by behroozam
# Twitter @b3hroozam
CSV_FILE_LOCATION = "./trim.csv"
PICTURES_SRC = "pictures/"
PICTURES_DST = "pictures-dst/"
LOG_FILE = "./rename.log"
def main():
picture_list = os.listdir(PICTURES_SRC)
with open(CSV_FILE_LOCATION ,'rt')as f:
drivers_data = csv.reader(f ,delimiter='\t')
done_list = []
for picture in drivers_data:
if picture[0] in picture_list:
dst = picture[1] + ".jpg"
src = PICTURES_SRC + picture[0]
dst = PICTURES_DST + dst
os.rename(src, dst)
done_list.append({
'src': src,
'dst': dst
})
log = open(LOG_FILE,'a+')
log.write(str(done_list) + '\n')
log.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment