diff --git a/Toolbox/filenamescrambleint.pyw b/Toolbox/filenamescrambleint.pyw new file mode 100644 index 0000000..4e6c001 --- /dev/null +++ b/Toolbox/filenamescrambleint.pyw @@ -0,0 +1,21 @@ +''' +Drag a file on top of this .py file, and it will have its +filename scrambled into a combination of 12 digits. +''' + +import os +import random +import string +import sys + +argv = sys.argv[1:] +print(argv) +for originalname in argv: + folder = os.path.dirname(originalname) + basename = os.path.basename(originalname) + extension = basename.split('.')[-1] + newname = [random.choice(string.digits) for x in range(12)] + newname = ''.join(newname) + newname = '%s/%s.%s' % (folder, newname, extension) + print('%s -> %s' % (originalname, newname)) + os.rename(originalname, newname) \ No newline at end of file diff --git a/Toolbox/fileprefix.py b/Toolbox/fileprefix.py new file mode 100644 index 0000000..8a731f1 --- /dev/null +++ b/Toolbox/fileprefix.py @@ -0,0 +1,46 @@ +''' +When you run this file from the commandline given a single argument, all +of the files in the current working directory will be renamed in the format +{argument}_{count} where argument is your cmd input and count is a zero-padded +integer that counts each file in the folder. +''' + +import os +import random +import string +import re +import sys + +assert len(sys.argv) == 2 + +prefix = sys.argv[1] +files = [os.path.abspath(x) for x in os.listdir()] +files = [item for item in files if os.path.isfile(item)] +if __file__ in files: + files.remove(__file__) + +# trust me on this. +zeropadding = len(str(len(files))) +zeropadding = max(2, zeropadding) +zeropadding = str(zeropadding) + +format = '%s_%0{pad}d%s'.format(pad=zeropadding) +print(format) + +def natural_sort(l): + ''' + http://stackoverflow.com/a/11150413 + ''' + convert = lambda text: int(text) if text.isdigit() else text.lower() + alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] + return sorted(l, key=alphanum_key) + +files = natural_sort(files) +for (fileindex, filename) in enumerate(files): + if '.' in filename: + extension = '.' + filename.split('.')[-1] + else: + extension = '' + newname = format % (prefix, fileindex, extension) + print(''.join([c for c in filename if c in string.printable]), '->', newname) + os.rename(filename, newname) \ No newline at end of file