Skip to content

Instantly share code, notes, and snippets.

@agtbaskara
Created January 30, 2023 07:38
Show Gist options
  • Save agtbaskara/a7801a41fb3217ff97fc6b615c9c3cee to your computer and use it in GitHub Desktop.
Save agtbaskara/a7801a41fb3217ff97fc6b615c9c3cee to your computer and use it in GitHub Desktop.
rename files in directory to orderly numbered filename
import os
import shutil
from tqdm import tqdm
from natsort import natsorted
if __name__ == '__main__':
dirlist = ['tut-sync/tut-ringroad/day/image_depth', 'tut-sync/tut-ringroad/night/image_depth',
'tut-sync/tut-backyard/day/image_depth', 'tut-sync/tut-backyard/night/image_depth']
for filedir in dirlist:
filelist = os.listdir(filedir)
filelist = natsorted(filelist, key=lambda y: y.lower())
print(filelist)
for index, filename in enumerate(tqdm(filelist)):
source_dir = os.path.join(filedir, filename)
destination_dir = os.path.join(filedir, 'images-' + str(index+1).zfill(5) + '.npy')
shutil.move(source_dir, destination_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment