トップ 履歴 一覧 Farm ソース 検索 ヘルプ PDF RSS ログイン

MarkAllDown.exe

*disclaimer
1373825

フォルダー内のオフィスファイルおよびPDFファイルをすべてマークダウン形式のファイルに変換するプログラム

  MS365Copilotに書いてもらったスクリプト


MarkItDownが事前にインストールしてあること

pip install "markitdown[all]"

pyinstallerも

pip install pyinstaller

変換するスクリプト convert_all.py とする

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from pathlib import Path
from markitdown import MarkItDown

# 変換対象拡張子
TARGET_EXTENSIONS = {
    ".pdf",
    ".docx",
    ".xlsx",
    ".xls",
    ".pptx"
}

md = MarkItDown()

def convert_file(filepath):
    try:
        result = md.convert(str(filepath))

        output_path = filepath.with_suffix(filepath.suffix + ".md")

        with open(output_path, "w", encoding="utf-8") as f:
            f.write(result.text_content)

        print(f"[OK] {filepath.name} -> {output_path.name}")

    except Exception as e:
        print(f"[ERROR] {filepath.name}: {e}")

def main():
    current_dir = Path.cwd()

    files = [
        f for f in current_dir.rglob("*")
        if f.is_file() and f.suffix.lower() in TARGET_EXTENSIONS
    ]

    print(f"{len(files)} files found.")

    for f in files:
        convert_file(f)

    print("Finished.")

if __name__ == "__main__":
    main()

実行ファイル化

pyinstaller --onefile convert_all.py


  作成した実行ファイルはこれです。

MarkAllDown.exe(34)

使い方


  1. フォルダーを作りその中に変換したいファイルを入れる
  2. その中にMarkAllDown.exeを入れる(たんにコピペでよい)
  3. MarkAllDown.exeをダブルクリックする(だけ)

  • 同じファイル名で、拡張子 .md を付けたファイルが作成される
  • すでにコンバートしたものが入っていても問題ない