Skip to content

Instantly share code, notes, and snippets.

@chiehpower
Created August 4, 2020 07:24
Show Gist options
  • Save chiehpower/22877f32ff14954c44ab4db879b37143 to your computer and use it in GitHub Desktop.
Save chiehpower/22877f32ff14954c44ab4db879b37143 to your computer and use it in GitHub Desktop.
import os
def batch_rename(path):
count = 0
total = len(os.listdir(path))
for fname in os.listdir(path):
time = total - len(str(count))
Extension = fname.split('.')[-1]
new_fname = str(0*(time)) + str(count) + '.' + Extension
print(os.path.join(path, fname), ' New file name >>> ', new_fname)
os.rename(os.path.join(path, fname), os.path.join(path, new_fname))
count = count + 1
path = input("Your data folder location")
# path = './dataset'
batch_rename(str(path))
@chiehpower
Copy link
Author

chiehpower commented Aug 4, 2020

There is a big issue in this script that if you implement more times, your some files will be covered to remove.
Again and again, and then it will remain few files.

Need to debug this issue...

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