Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Created March 22, 2016 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgeeky/bd4793c6951bb11127cd to your computer and use it in GitHub Desktop.
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.
#!/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