Skip to content

Python 3, Recreate directory structure from Json

Notifications You must be signed in to change notification settings

tmdag/makedirtree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python 3, Linux MakeDirTree

VFX Pipeline python v3.6 pylint Score

GitHub: https://github.com/tmdag/makedirtree

Overview

Recreates directory structure from given json file.

Requiremenets:

Json Parser This module is using 'jsonParser' module (wrapper on top of native python 'json'module ) It should be installed automatically through dependencies

Installation:

$ pip install git+http://github.com/tmdag/makedirtree

Usage:

  • Create directory structure from current directory (and its children) and save structure to json file using built in linux command:
$ 'tree -Jd . > folderTemplate.json'

Or from Python subprocess:

import subprocess
data = subprocess.run(["tree", "-Jd", "/path/to/dir"], stdout=subprocess.PIPE)
print(data.stdout)
  • Recreate directory structure from saved json file, starting from provided directory and your project name
from jsonparser import JsonFile
Structures("/home/Projects/", template_file="folderTemplate.json").create("Project002")

Example:

Each of your projects has same directory structure:

$ /home/Projects/Project001 >  tree -d .
.
├── out
│   ├── folder01
│   └── folder02
├── sceneFiles
│   ├── folder01
│   │   └── backup
│   └── folder02
├── render
│   └── folder01
│       └── folder01
└── source

and you want to create a new, Project002 with same directory structure.

You can save current directory structure to file:
$ /home/Projects/Project001 >  'tree -Jd . > folderTemplate.json'

and using python, recreate this structure:
from jsonparser import JsonFile

PROJECTS_PARENT_DIR = "/home/Projects/"
STRUCTURE_TEMPLATE_FILE = "/config/folderTemplate.json"
NEW_PROJECT_NAME = "Project002"

dir_structure = SetupTree(PROJECTS_PARENT_DIR, template_file=STRUCTURE_TEMPLATE_FILE)
# dir_structure.test_structure(NEW_PROJECT_NAME)
dir_structure.create_new_project(NEW_PROJECT_NAME)

About

Python 3, Recreate directory structure from Json

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages