#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. """Rename all files in the given directory Allows the current dir or chosen dir Will append an extention given """ __all__ = ['main', 'input_opts'] __author__ = "Cody A. Taylor ( codemister99@yahoo.com )" __version__ = "0.2 alpha" import os, sys def main(): extention, dir = input_opts() for filename in sorted(os.listdir(dir)): new_name = input('Rename "{}" to: '.format(filename)) if not new_name.endswith(extention): new_name += extention os.rename(dir + os.sep + filename, dir + os.sep + new_name) def input_opts(): if len(sys.argv) == 1: extention = input("Extention: ") dir = input("Directory [default {}]: ".format(os.getcwd())) or "." print(dir) else: if "--help" in sys.argv[1:]: print("Usage: {} [extention] [dir]".format(sys.argv[0]), "Changes the name of all files in the given dir [default: $PWD]", sep="\n") sys.exit(0) else: extention = sys.argv[1] try: dir = sys.argv[2] except IndexError: dir = "." return extention, dir if __name__ == "__main__": main()