Last active
November 14, 2018 08:22
-
-
Save rexlow/445d2eeb1cd8e649d1ffda36178e01a3 to your computer and use it in GitHub Desktop.
Simple Python script to rename all files in a directory
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Tuesday Nov 13 | |
This script is to rename all files in a directory according to a pattern without changing file extension | |
@author: Rex Low | |
@github: rexlow | |
""" | |
import os | |
def rename(fdir, startIdx): | |
i = startIdx | |
for _, f in enumerate(os.listdir(fdir)): | |
if f.lower().endswith((".jpg", ".png", ".jpeg")): | |
src = os.path.join(fdir, f) | |
dst = os.path.join(fdir, "plate{}{}".format(i, os.path.splitext(f)[1])) | |
os.rename(src, dst) | |
i += 1 | |
rename("/Users/rex/Desktop/images/crawl", 428) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment