Last active
August 7, 2020 03:17
-
-
Save LeiHao0/b832ca86a85c3a87239ceafda005a200 to your computer and use it in GitHub Desktop.
renameExt.py
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
# usage | |
# py renameExt.py folder oldExt newExt | |
import os | |
import sys | |
folder = sys.argv[1] | |
oldExt = f".{sys.argv[2]}" | |
newExt = f".{sys.argv[3]}" | |
print(folder, oldExt, newExt) | |
for (dirpath, dirnames, filenames) in os.walk(folder): | |
for filename in filenames: | |
pre, ext = os.path.splitext(str(filename)) | |
if ext == oldExt: | |
oriFullPath = os.sep.join([dirpath, filename]) | |
newFullPath = os.sep.join([dirpath, pre + newExt]) | |
print(oriFullPath, ' -> ', newFullPath) | |
os.rename(oriFullPath, newFullPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment