Skip to content

Instantly share code, notes, and snippets.

@ola0x
Created March 24, 2022 23:32
Show Gist options
  • Save ola0x/ca6d3203dc47b47ab01c0535bbd1868a to your computer and use it in GitHub Desktop.
Save ola0x/ca6d3203dc47b47ab01c0535bbd1868a to your computer and use it in GitHub Desktop.
# Python program to rename all file
# names in your directory
import os
os.chdir(r'C:\Users\oolaonipekun\Desktop\Car_damage_detection\data\validation\whole')
print(os.getcwd())
COUNT = 1
# Function to increment count
# to make the files sorted.
def increment():
global COUNT
COUNT = COUNT + 1
for f in os.listdir():
f_name, f_ext = os.path.splitext(f)
f_name = "valid_whole" + str(COUNT)
increment()
new_name = '{} {}'.format(f_name, f_ext)
os.rename(f, new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment