Last active
December 3, 2019 04:42
-
-
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
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
| 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