Created
June 28, 2016 12:59
-
-
Save samuelsh/b837f8ab8b33c344f01128568dd12019 to your computer and use it in GitHub Desktop.
Python directory tree generator, using recursion
This file contains 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/python2.6 | |
import sys | |
import os | |
def build_dir_tree(base, depth, width): | |
print("Call #%d" % depth) | |
if depth >= 0: | |
curr_depth = depth | |
depth -= 1 | |
for i in xrange(width): | |
# first creating all folder at current depth | |
os.makedirs('%s/Dir_#%d_level_%d' % (base, i, curr_depth)) | |
dirs = os.walk(base).next()[1] | |
for dir in dirs: | |
newbase = os.path.join(base,dir) | |
build_dir_tree(newbase, depth, width) | |
else: | |
return | |
if not sys.argv[1:]: | |
print('No base path given') | |
sys.exit(1) | |
print('path: %s, depth: %d, width: %d' % (sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))) | |
build_dir_tree(sys.argv[1], int(sys.argv[2]), int(sys.argv[3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment