Skip to content

Instantly share code, notes, and snippets.

@swayson
Last active March 12, 2017 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swayson/ed6b7a8c0481cd266bebeccb787afb31 to your computer and use it in GitHub Desktop.
Save swayson/ed6b7a8c0481cd266bebeccb787afb31 to your computer and use it in GitHub Desktop.
Simple python cli application to construct directories according to specifications.
import os
import click
def read_file(filename):
with open(filename) as in_file:
for line in in_file:
if line.strip() != '':
yield line.strip()
@click.command()
@click.argument('template', type=click.Path(), required=True)
@click.argument('root', type=click.Path(), required=False)
def create(template, root):
""" Creates a directory structure according to a given template.
Parameters
----------
template : string
filename of template file. template file is a text file
where each line represents a folder uses a relative path notation.
e.g. /path/to/somewhere
root : string
Path in which the folders will be created. If None provided, will use
current working directory.
Usage
-----
$ python standard_folders.py template.txt project/
"""
print("Starting.")
if root is None:
root = os.getcwd()
print(root)
for item in read_file(template):
if not os.path.exists(item):
filename = os.path.join(root, item)
print("Making folder... {}".format(filename))
os.makedirs(filename, mode=755)
print("Done.")
if __name__ == '__main__':
create()
audio
audio/music
audio/meditation
audio/podcasts
audio/talks
video
video/movies
video/talks
video/lectures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment