Skip to content

Instantly share code, notes, and snippets.

@martinusso
Last active August 29, 2015 13:55
Show Gist options
  • Save martinusso/8698720 to your computer and use it in GitHub Desktop.
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]
#!/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