Created
March 6, 2019 18:21
-
-
Save bohdon/58e1ea28ee375c806d44b780a763dcee to your computer and use it in GitHub Desktop.
Create .placeholder files in any empty leaf directories
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 | |
| 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