Skip to content

Instantly share code, notes, and snippets.

@jrsa
Created June 17, 2017 18:48
Show Gist options
  • Save jrsa/8215fb8d38f062fe4a3ca7bc92bcc22b to your computer and use it in GitHub Desktop.
Save jrsa/8215fb8d38f062fe4a3ca7bc92bcc22b to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
"""
R andom R ecursive R ename
obfuscate the names of a bunch of stuff whilst preserving directory structure
"""
from random import randint
from os import *
import sys
def rrr(dir):
# recursively walk all directories from `dir`
for dirpath, dirnames, filenames in walk(dir):
# every file in a given directory
for f in filenames:
# the full path to each file
filepath = path.join(dirpath, f)
# just the extension
fn, ext = path.splitext(f)
# rename expects full paths, so join the path with the
# random filename and the extension
newpath = path.join(dirpath, randfn() + ext)
rename(filepath, newpath)
def randfn():
return hex(randint(0, pow(2, 32)))
try:
base_dir = sys.argv[1]
except IndexError as e:
print("{} <starting directory>".format(sys.argv[0]))
exit(-1)
answer = raw_input(
"rename everything in {}? (yes to confirm): ".format(base_dir))
if answer == 'yes':
rrr(base_dir)
else:
print("cancelled")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment