SimonXIX / Markdown_translation

a script and Docker environment for running automated open source translations of batches of Markdown files using LibreTranslate
GNU Affero General Public License v3.0
6 stars 1 forks source link

Suggestion: paths with pathlib.Path #1

Closed villares closed 9 months ago

villares commented 9 months ago

Hi, thanks for the repo!

Would you like me to try my hand at a PR to convert your basedirectory walk to a pathlib equivalent?

# iterate over files in the input directory
for subdir, dirs, files in os.walk(input_directory):
    for file in files:
        # file name with extension
        file_name = os.path.basename(file)
        read_file = subdir + '/' + file_name

        # read Markdown file
        text = frontmatter.load(read_file)

maybe something like:

from pathlib import Path

# iterate over files in the input directory
for file_path in Path(input_directory).rglob("*.*"):    # or *.md ?
    # read Markdown file
    text = frontmatter.load(file_path)
SimonXIX commented 9 months ago

Oh please do! Thanks.