Update filenamescrambleint.
This commit is contained in:
parent
9ed28ac6b0
commit
c40bc4be54
2 changed files with 58 additions and 18 deletions
|
@ -1,20 +1,41 @@
|
|||
'''
|
||||
Drag a file on top of this .py file, and it will have its
|
||||
filename scrambled into a combination of 12 digits.
|
||||
Drag multiple files on top of this .py file and their names will be scrambled
|
||||
into random digits.
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
|
||||
from voussoirkit import betterhelp
|
||||
from voussoirkit import pathclass
|
||||
from voussoirkit import vlogging
|
||||
|
||||
argv = sys.argv[1:]
|
||||
log = vlogging.getLogger(__name__, 'filenamescrambleint')
|
||||
|
||||
for path in sorted(pathclass.glob_many(argv), key=pathclass.natural_sorter):
|
||||
newname = [random.choice(string.digits) for x in range(12)]
|
||||
newname = ''.join(newname) + path.dot_extension
|
||||
def filenamescrambleint_argparse(args):
|
||||
length = int(args.length)
|
||||
|
||||
for path in sorted(pathclass.glob_many(args.patterns), key=pathclass.natural_sorter):
|
||||
randname = [random.choice(string.digits) for x in range(length)]
|
||||
randname = int(''.join(randname))
|
||||
newname = str(randname).rjust(length, '0') + path.dot_extension
|
||||
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=filenamescrambleint_argparse)
|
||||
|
||||
return betterhelp.go(parser, argv)
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
|
|
|
@ -4,21 +4,40 @@ name randomly scrambled into 12 digits. The others will increment that number
|
|||
by 1.
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
|
||||
from voussoirkit import betterhelp
|
||||
from voussoirkit import pathclass
|
||||
from voussoirkit import vlogging
|
||||
|
||||
argv = sys.argv[1:]
|
||||
log = vlogging.getLogger(__name__, 'filenamescrambleordered')
|
||||
|
||||
randname = [random.choice(string.digits) for x in range(12)]
|
||||
def filenamescrambleordered_argparse(args):
|
||||
length = int(args.length)
|
||||
randname = [random.choice(string.digits) for x in range(length)]
|
||||
randname = int(''.join(randname))
|
||||
|
||||
for path in sorted(pathclass.glob_many(argv), key=pathclass.natural_sorter):
|
||||
newname = str(randname).rjust(12, '0') + path.dot_extension
|
||||
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:]))
|
||||
|
|
Loading…
Reference in a new issue