Last active
August 29, 2015 13:55
-
-
Save martinusso/8698720 to your computer and use it in GitHub Desktop.
Script to change the extension of multiple files in a directory with Python. [pt-br: Script para mudar a extenção de multiplos arquivos usando Python]
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/python | |
# coding: utf-8 | |
import os | |
OLD_EXT = '.rar' # Change here for the old extension | |
NEW_EXT = '.cbr' # Change here for the new extension | |
CURRENT_DIR = os.getcwd() | |
def main(): | |
for f in os.listdir(CURRENT_DIR): | |
old_file = os.path.join(CURRENT_DIR, f) | |
filename, ext = os.path.splitext(f) | |
if ext == OLD_EXT: | |
new_file = old_file.replace(OLD_EXT, NEW_EXT) | |
os.rename(old_file, new_file) | |
print 'done!' | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment