diff --git a/Software/Tools/ChangeExtension.py b/Software/Tools/ChangeExtension.py new file mode 100644 index 0000000..fd544dd --- /dev/null +++ b/Software/Tools/ChangeExtension.py @@ -0,0 +1,33 @@ +##################### +# +# Author: F. Lionetto +# Date: 07/10/2014 +# + +''' +Change the extension of all files in a given directory. + +Run with: + +python ChangeExtension.py --f --o --n +''' + +import argparse +import os, sys + +parser = argparse.ArgumentParser(description='Define directory, old extension, and new extension.') +# Define folder. +parser.add_argument('--f',type=str,help='directory') +# Define old extension. +parser.add_argument('--o',type=str,help='old extension') +# Define new extension. +parser.add_argument('--n',type=str,help='new extension') +args = parser.parse_args() + +directory = args.f +for filename in os.listdir(directory) : + infilename = os.path.join(directory,filename) + if not os.path.isfile(infilename) : continue + oldbase = os.path.splitext(filename) + newname = infilename.replace(args.o,args.n) + output = os.rename(infilename,newname)