Add option to start index from 1.

This commit is contained in:
voussoir 2020-11-02 16:23:32 -08:00
parent 907842d5cc
commit 8ec117bfe0

View file

@ -31,6 +31,7 @@ def fileprefix(
sep='_', sep='_',
ctime=False, ctime=False,
autoyes=False, autoyes=False,
one_index=False,
): ):
current_directory = pathclass.cwd() current_directory = pathclass.cwd()
@ -66,7 +67,8 @@ def fileprefix(
rename_pairs = [] rename_pairs = []
for (index, filepath) in enumerate(filepaths): start_index = 1 if one_index else 0
for (index, filepath) in enumerate(filepaths, start_index):
extension = filepath.extension.with_dot extension = filepath.extension.with_dot
newname = format.format(prefix=prefix, index=index, extension=extension) newname = format.format(prefix=prefix, index=index, extension=extension)
@ -83,10 +85,11 @@ def fileprefix(
def fileprefix_argparse(args): def fileprefix_argparse(args):
return fileprefix( return fileprefix(
autoyes=args.autoyes,
ctime=args.ctime,
one_index=args.one_index,
prefix=args.prefix, prefix=args.prefix,
sep=args.sep, sep=args.sep,
ctime=args.ctime,
autoyes=args.autoyes,
) )
def main(argv): def main(argv):
@ -96,6 +99,7 @@ def main(argv):
parser.add_argument('--sep', dest='sep', default=' ', help='the character between the prefix and remainder') parser.add_argument('--sep', dest='sep', default=' ', help='the character between the prefix and remainder')
parser.add_argument('--ctime', dest='ctime', action='store_true', help='sort by ctime instead of filename') parser.add_argument('--ctime', dest='ctime', action='store_true', help='sort by ctime instead of filename')
parser.add_argument('-y', '--yes', dest='autoyes', action='store_true', help='accept results without confirming') parser.add_argument('-y', '--yes', dest='autoyes', action='store_true', help='accept results without confirming')
parser.add_argument('-1', dest='one_index', action='store_true')
parser.set_defaults(func=fileprefix_argparse) parser.set_defaults(func=fileprefix_argparse)
args = parser.parse_args(argv) args = parser.parse_args(argv)