Skip to content

Instantly share code, notes, and snippets.

@mark-ingenosity
Last active December 3, 2019 04:42
Show Gist options
  • Select an option

  • Save mark-ingenosity/c31b639d1055855b23add70d1d86305a to your computer and use it in GitHub Desktop.

Select an option

Save mark-ingenosity/c31b639d1055855b23add70d1d86305a to your computer and use it in GitHub Desktop.
[PYTHON: File Management: Tabbed List to Hierarchical Folder Structure]Reads a tabbed text file and maps text entries to the creation of a structured folder hierachy. #textfile #process #filesystem #create
import os, sys
with open(sys.argv[1]) as f:
res=[]
s=[]
for line in f:
line=line.rstrip()
x=len(line)
line=line.lstrip()
indent=2*(x-len(line))
s=s[:indent/2]+[line]
path="/".join(s)
print path
try:
os.makedirs(path)
except OSError:
print ("Creation of the directory failed.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment