Created
March 22, 2016 18:01
-
-
Save mgeeky/bd4793c6951bb11127cd to your computer and use it in GitHub Desktop.
Creates nested directories structure. May come handy in testing utilities recursive path-traversing algorithms, their recursion limits as well as during preparation of Zip Bombs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os, sys | |
g_ABC = 0 | |
def recurrent_mkdir( path, lvl, dirs ): | |
if lvl == 0: | |
return | |
for a in range(dirs): | |
s = '' | |
if g_ABC == 0: | |
s = `a` | |
else: | |
# 65 in decimal is 'A' | |
s = chr(int(65)+a) | |
p = os.path.join( path, s) | |
try: | |
os.mkdir( p ) | |
except: | |
pass | |
recurrent_mkdir( p, lvl-1, dirs) | |
if __name__ == '__main__': | |
if len( sys.argv) == 1: | |
print '\nUsage: numberizer.py path_for_struct [nesting_lvl][abc]\n' | |
print '\tpath_for_struct - place where the structure will be'\ | |
'created\n\tnesting_lvl - the deepest directory level' | |
print '\tabc - pushes to name directories in alphabet letters instead of numbers' | |
sys.exit(0) | |
path = sys.argv[1] | |
lvl = 6 | |
if len(sys.argv) > 2: | |
if int(sys.argv[2]) > 0: | |
lvl = int(sys.argv[2]) | |
if len(sys.argv) > 3: | |
g_ABC = 1 | |
try: | |
os.chdir(path) | |
except: | |
print '[!] Input path is not accessible !' | |
sys.exit(0) | |
no = lvl**lvl + lvl | |
print '\n\t[+] Working directory: \''+os.getcwd() | |
print '\t[+] Have to make '+ `no` | |
raw_input( '\tHit enter to engage...') | |
recurrent_mkdir( path, lvl, lvl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment