2019-06-12 05:41:31 +00:00
|
|
|
'''
|
|
|
|
Drag multiple files on top of this .py file. The first file will have its
|
2021-12-22 00:58:10 +00:00
|
|
|
name randomly scrambled into 12 digits. The others will increment that number
|
|
|
|
by 1.
|
2019-06-12 05:41:31 +00:00
|
|
|
'''
|
|
|
|
|
2022-11-11 23:26:35 +00:00
|
|
|
import argparse
|
2019-06-12 05:41:31 +00:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
import sys
|
|
|
|
|
2022-11-11 23:26:35 +00:00
|
|
|
from voussoirkit import betterhelp
|
2020-02-06 05:48:37 +00:00
|
|
|
from voussoirkit import pathclass
|
2022-11-11 23:26:35 +00:00
|
|
|
from voussoirkit import vlogging
|
2020-02-06 05:48:37 +00:00
|
|
|
|
2022-11-11 23:26:35 +00:00
|
|
|
log = vlogging.getLogger(__name__, 'filenamescrambleordered')
|
2019-06-12 05:41:31 +00:00
|
|
|
|
2022-11-11 23:26:35 +00:00
|
|
|
def filenamescrambleordered_argparse(args):
|
|
|
|
length = int(args.length)
|
|
|
|
randname = [random.choice(string.digits) for x in range(length)]
|
|
|
|
randname = int(''.join(randname))
|
2021-09-24 06:42:34 +00:00
|
|
|
|
2022-11-11 23:26:35 +00:00
|
|
|
for path in sorted(pathclass.glob_many(args.patterns), key=pathclass.natural_sorter):
|
|
|
|
newname = str(randname).rjust(length, '0') + path.dot_extension
|
|
|
|
randname += 1
|
|
|
|
newname = path.parent.with_child(newname)
|
|
|
|
os.rename(path, newname)
|
|
|
|
print('%s -> %s' % (path.absolute_path, newname.basename))
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
@vlogging.main_decorator
|
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('patterns', nargs='+')
|
|
|
|
parser.add_argument('--length', default=12)
|
|
|
|
parser.set_defaults(func=filenamescrambleordered_argparse)
|
|
|
|
|
|
|
|
return betterhelp.go(parser, argv)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|