Created
January 30, 2023 07:38
-
-
Save agtbaskara/a7801a41fb3217ff97fc6b615c9c3cee to your computer and use it in GitHub Desktop.
rename files in directory to orderly numbered filename
This file contains 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
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