from Qt import QtWidgets,QtCore,QtGui import pymel.core as pm from functools import partial import Qt import logging from maya import OpenMayaUI as omui
if Qt.__binding__ == 'PySide': logger.debug('Using Pyside with shiboken') from shiboken import warpInstance from Qt.QtCore import Signal elif Qt.__binding__.startswith('PyQt'): logger.debug('Using PyQt with sip') from sip import warpInstance as warpInstance from Qt.QtCore import pyqtSignal as Signal else: logger.debug('Using PySide2 with shiboken') import shiboken2 from Qt.QtCore import Signal
defmain(): parser = argparse.ArgumentParser(description = "This is a batch renamer", usage = "To replace all files with hello with goodbye instead: python clirenamer.py hello goodbye") parser.add_argument('inString', help = "The world to replace") parser.add_argument('outString', help = "The world to replace it with") parser.add_argument('-d', '--duplicate', help = "Whether to duplicate or replace in spot", action = 'store_true')#默认为False parser.add_argument('r', '--regex', help = "Whether the patterns are regex or not", action = "store_true") parser.add_argument('o', '--out', help = "The output location. Defaults to here") args = parser.parser_args() print(args) rename(args.inString,args.outString, duplicate = args.duplicate, outDirectory = args.out, regex = args.regex) defrename(inString, outString, duplicate = True, inDirectory = None, outDirectory = None, regex = False): ifnot inDirectory: inDirectory = os.getcwd() ifnot outDirectory: outDIrectory = inDirectory outDirectory = os.path.abspath(outDirectory) ifnot os.path.exists(outDirectory): raise IOError('{} does not exist'.format(outDirectory)) ifnot os.path.exists(inDirectory): raise IOError('{} does not exist'.format(inDirectory)) for f in os.listdir(inDirectory): if .startwith('.'):#linux,mac中.开头表示隐藏文件 continue if regex: name = re.sub(inString, outString, f) else: name = f.replace(inString, outString) print(name) if name == f: continue src = os.path.join(inDirectory, f) dest = os.path.join(outDirectory, name) if duplicate: shutil.copy2(src, dest) else: os.rename(src, dest) if __name__ == '__main__':z main()#分离命名空间,只有当这个文件命名空间是main的时候才运行