Skip to content

Instantly share code, notes, and snippets.

@daguiam
Created October 15, 2020 11:56
Show Gist options
  • Save daguiam/43f1e5eae370f0cb674aa032aaf51784 to your computer and use it in GitHub Desktop.
Save daguiam/43f1e5eae370f0cb674aa032aaf51784 to your computer and use it in GitHub Desktop.
import os
def walk_levels(inputpath, outputpath, levels=1):
if levels==0:
return
else:
if not os.path.isdir(outputpath):
os.mkdir(outputpath)
for dirpath in os.listdir(inputpath):
newinput = os.path.join(inputpath, dirpath)
structure = os.path.join(outputpath, dirpath)
if not os.path.isdir(newinput):
continue
print(structure)
if not os.path.isdir(structure):
# print("creating dir")
os.mkdir(structure)
walk_levels(newinput, structure, levels-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment