Last active
July 1, 2019 19:29
-
-
Save devforfu/4b8a7931026b8a5c2b623beed6aa65de to your computer and use it in GitHub Desktop.
Converting function into CLI
This file contains 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
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