Skip to content

Instantly share code, notes, and snippets.

@devforfu
Last active July 1, 2019 19:29
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 devforfu/4b8a7931026b8a5c2b623beed6aa65de to your computer and use it in GitHub Desktop.
Save devforfu/4b8a7931026b8a5c2b623beed6aa65de to your computer and use it in GitHub Desktop.
Converting function into CLI
from pathlib import Path
def concat(folder: str, output: str = 'concat.txt', include_names: bool = True):
"""Concatenates a list of files from a folder and saves them into a single file."""
p = Path(folder)
files = []
for filename in p.iterdir():
content = filename.open('r').read().strip()
if include_names:
content = f'{filename}\n{content}\n'
files.append(content)
single = '\n'.join(files)
Path(output).open('w').write(single)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment