#-----This Python code uses a very elementary approach to add a prefix to all # files of specified type (extension) in a folder. This code should be placed # in the folder which contains the files. #------------------------------------------------------------------------------ import sys, subprocess, shutil import fitz import os, re #------------------------------------------------------------------------------ if (len(sys.argv) < 3): print("Usage: python3 {} prefix extension num_chars \n".format(sys.argv[0])) sys.exit(1) #------------------------------------------------------------------------------ #Get the new prefix prefix = str(sys.argv[1]) #Get file type (extension without dot) extn = str(sys.argv[2]) #Get number of characters to be stripped at the begenning of the file names nchar = int(sys.argv[3]) #Get teh new suffix: not implemented in this script #suffix = str(sys.argv[3]) folder = os.getcwd() for path, subdirs, files in os.walk(folder): for name in files: fn = name[nchar:] #print(fn) ext = os.path.splitext(fn)[-1].lower() ext = ext.partition('.')[2] if (ext == extn): new_name = prefix + fn os.rename(name, new_name)