Last active
April 23, 2020 17:28
-
-
Save edwindotcom/0998fac1485e4c9c56b5553fac482259 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Renames all the files in a directory with the root filename | |
# To run this: | |
# $ python pymv.py MyFileNameRoot | |
# > Renaming: Screen Shot 2020-04-23 at 10.07.21 AM.png => flare0.png | |
import os | |
import sys | |
# Function to rename multiple files | |
def main(): | |
if(len(sys.argv) < 2): | |
print("Please pass filename into command") | |
print("Example: python pymv.py NewFilename") | |
exit() | |
for count, filename in enumerate(os.listdir(".")): | |
if filename == "pymv.py": | |
continue | |
ext = filename.rsplit('.', 1)[1] | |
new_name = "{}{}.{}".format(sys.argv[1],str(count), ext) | |
print "Renaming: {} => {}".format(filename, new_name) | |
# os.rename(filename, new_name) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment