2016-12-05 01:50:52 +00:00
|
|
|
'''
|
|
|
|
Batch rename files by replacing the first argument with the second.
|
|
|
|
'''
|
2019-04-17 01:39:33 +00:00
|
|
|
import argparse
|
2016-12-02 06:37:07 +00:00
|
|
|
import brename
|
|
|
|
import sys
|
|
|
|
|
2019-04-17 01:39:33 +00:00
|
|
|
def breplace_argparse(args):
|
|
|
|
command = f'x.replace("{args.replace_from}", "{args.replace_to}")'
|
|
|
|
brename.brename(command, autoyes=args.autoyes)
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(__doc__)
|
|
|
|
|
|
|
|
parser.add_argument('replace_from')
|
|
|
|
parser.add_argument('replace_to')
|
|
|
|
parser.add_argument('-y', '--yes', dest='autoyes', action='store_true', help='accept results without confirming')
|
|
|
|
parser.set_defaults(func=breplace_argparse)
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
args.func(args)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|