Created
December 24, 2020 00:38
-
-
Save vedantroy/ab8915b7f559888012f64500f1964b46 to your computer and use it in GitHub Desktop.
Rename the files in a directory as 0, 1, 2,... in sorted order
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
#! /usr/bin/env python3 | |
import os | |
import sys | |
if len(sys.argv) < 2: | |
print("Usage [exe name] [dir name]") | |
exit(1) | |
dir = sys.argv[1] | |
for i, filename in enumerate(sorted(os.listdir(dir))): | |
_, ext = os.path.splitext(filename) | |
new_name = f"{dir}/{i}{ext}" | |
os.rename(os.path.join(dir, filename), new_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment