Skip to content

Instantly share code, notes, and snippets.

@bohdon
Created March 6, 2019 18:21
Show Gist options
  • Select an option

  • Save bohdon/58e1ea28ee375c806d44b780a763dcee to your computer and use it in GitHub Desktop.

Select an option

Save bohdon/58e1ea28ee375c806d44b780a763dcee to your computer and use it in GitHub Desktop.
Create .placeholder files in any empty leaf directories
import os
import sys
import click
@click.command()
@click.argument("root_path")
def build(root_path):
root_path = os.path.abspath(root_path)
if not os.path.isdir(root_path):
print('Path does not exist: {}'.format(root_path))
sys.exit(1)
for dirpath, dirnames, filenames in os.walk(root_path):
if not dirnames and not filenames:
print(dirpath)
create_placeholder(dirpath)
def create_placeholder(dirpath):
"""
Create a .placeholder file in the given directory
"""
filepath = os.path.join(dirpath, '.placeholder')
if not os.path.isfile(filepath):
with open(filepath, 'w'):
pass
print('Created {}'.format(filepath))
if __name__ == '__main__':
build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment