else/Toolbox/filenamescramble.py

24 lines
675 B
Python
Raw Normal View History

2015-08-20 06:58:19 +00:00
'''
Drag a file on top of this .py file, and it will have its
filename scrambled into a combination of 16 upper and lowercase
letters.
'''
import os
import random
import string
import sys
argv = sys.argv[1:]
2016-01-17 01:43:17 +00:00
print(''.join(c for c in argv if c in string.printable))
for filepath in argv:
folder = os.path.dirname(filepath)
basename = os.path.basename(filepath)
extension = os.path.splitext(basename)[1]
2016-05-10 08:00:29 +00:00
newname = [random.choice(string.ascii_lowercase) for x in range(9)]
2015-08-20 06:58:19 +00:00
newname = ''.join(newname)
2016-05-10 08:00:29 +00:00
newname = newname + extension
newname = os.path.join(folder, newname)
#os.rename(filepath, newname)
print('%s -> %s' % (filepath, newname))