# Batch conversion with MarkItDown

> How to convert a whole folder with MarkItDown 0.1.9: a shell loop, one Python process or a process pool, with timings for 400 files and how failures behave.

Source: https://markitdown.dev/batch/ · Updated 2026-11-16·Upstream source ↗

The command converts one file per run, and each run spends about a second starting Python. For a folder, use one Python process that reuses a single converter: 400 files took 27 seconds that way and 402 seconds as one command per file in our test.

> **Short answer**
>
> In Python, create one `MarkItDown()`, loop over the files, and catch errors per file:
> 
> ```python
> from pathlib import Path
> from markitdown import MarkItDown
> 
> md = MarkItDown()                                   # one converter for the whole run
> out_dir = Path("converted"); out_dir.mkdir(exist_ok=True)
> ok, failed = 0, []
> for path in sorted(Path("samples").glob("*")):
>     if path.suffix.lower() not in {".docx", ".xlsx", ".pptx", ".pdf", ".csv", ".html"}:
>         continue                                    # skip types we did not ask for
>     try:
>         text = md.convert(path).markdown
>         (out_dir / (path.name + ".md")).write_text(text, encoding="utf-8")
>         ok += 1
>     except Exception as e:                          # one bad file must not stop the run
>         failed.append((path.name, type(e).__name__))
> print(f"converted {ok}, failed {len(failed)}")
> for name, err in failed: print("  failed:", name, err)
> ```
> 
> Output · markitdown 0.1.9 · Python 3.13.18 · 2026-11-16
> 
> ```
> converted 46, failed 1
>   failed: pdf-encrypted.pdf FileConversionException
> ```
> 
> [captured result](https://markitdown.dev/evidence/snippets/api-batch-folder/result.json)

Tested with markitdown 0.1.9 · Python Linux lab, 4 CPU cores, Python 3.13, markitdown 0.1.9; 47 sample files for the folder run, 400 copies for the timings (T15, T09) · 2026-11-16 · evidence: [batch-modes.csv](https://markitdown.dev/data/batch-modes.csv), [bash-loop.log](https://markitdown.dev/evidence/T15/bash-loop.log)

## A shell loop: simple, slow

```bash
for f in *.docx *.xlsx *.pptx; do markitdown "$f" -o "${f%.*}.md"; done
```

This works, but it starts Python for every file. We timed 400 files this way at about 1 file a second.

## One process, one converter

The Python loop above converted 46 of the 47 files in our sample folder and reported the one that failed, an encrypted PDF, instead of stopping. Reuse one converter: creating it loads the file-type model, which is most of the cost of a small file ([speed page](https://markitdown.dev/performance/)).

## In parallel

```python
from concurrent.futures import ProcessPoolExecutor
from pathlib import Path
from markitdown import MarkItDown

def convert_chunk(paths):
    md = MarkItDown()                               # one converter per worker process
    return [(p, len(md.convert(p).markdown)) for p in paths]

if __name__ == "__main__":                          # required for process pools on Windows and macOS
    files = [str(p) for p in sorted(Path("samples").glob("*.docx"))] + [str(p) for p in sorted(Path("samples").glob("*.xlsx"))]
    chunks = [files[i::2] for i in range(2)]        # two workers
    with ProcessPoolExecutor(2) as pool:
        for chunk in pool.map(convert_chunk, chunks):
            for name, n in chunk: print(f"{Path(name).name:<28} {n:>6} characters")
```

Output · markitdown 0.1.9 · Python 3.13.18 · 2026-11-16

```
docx-bullets.docx                48 characters
docx-image-alt.docx              61 characters
docx-merged-cells.docx          121 characters
docx-nested-lists.docx          112 characters
docx-table-header.docx           97 characters
docx-table-pipe.docx             61 characters
report.docx                     838 characters
xlsx-blank-rows-cols.xlsx       111 characters
xlsx-formulas-recalculated.xlsx     72 characters
xlsx-header-row3-merged-hidden.xlsx    357 characters
xlsx-int-blank.xlsx              73 characters
xlsx-number-formats.xlsx        401 characters
xlsx-sheets.xlsx                118 characters
docx-custom-styles.docx          41 characters
docx-images-no-alt.docx         103 characters
docx-nested-bullets.docx         54 characters
docx-pipe-newline-table.docx    106 characters
docx-table-no-header.docx       108 characters
docx-title-subtitle.docx         64 characters
workbook.xlsx                   526 characters
xlsx-empty-hidden.xlsx          115 characters
xlsx-formulas-uncached.xlsx      77 characters
xlsx-header-row3.xlsx           132 characters
xlsx-merged-header.xlsx         143 characters
xlsx-pipe-newline.xlsx           86 characters
```

[captured result](https://markitdown.dev/evidence/snippets/api-batch-pool/result.json)

400 small files on 4 CPU cores
| Mode | Seconds | Files per second |
| --- | --- | --- |
| command line, one process per file (40 files, scaled to 400) | 402.3 | 1.0 |
| one Python process, one MarkItDown reused | 27.3 | 14.6 |
| process pool, 2 workers, one MarkItDown each | 23.7 | 16.9 |
| process pool, 4 workers, one MarkItDown each | 23.1 | 17.3 |
| thread pool, 4 threads, one shared MarkItDown (empty results: 0) | 30.1 | 13.3 |

*400 small files on 4 CPU cores Source: Test T15 · 2026-11-16 · one run each · batch-modes.csv · Download CSV*

Workers helped only a little on small files (17 against 15 files a second), because each worker also starts up. A thread pool sharing one converter worked without errors but was slower. Parallelism pays off more with large files; we did not measure that.

## Failures and what to do about them

A failed file raises an exception; catch it per file (the first snippet does). Scanned files return an empty result with no exception, so check the output length ([OCR](https://markitdown.dev/ocr/)). Missing extras raise `MissingDependencyException` ([missing dependency](https://markitdown.dev/errors/missing-dependency/)).

## Not tested

PowerShell and Command Prompt loops, converting from a queue, and progress reporting.

## Related

- [Speed and memory](https://markitdown.dev/performance/): Speed and memory in detail.
- [CLI reference](https://markitdown.dev/cli/): The command line.
- [Python API guide](https://markitdown.dev/python-api/): The Python API.
- [Error reference](https://markitdown.dev/errors/): Error messages.

---
Independent guide to the open-source MarkItDown library. Not affiliated with or endorsed by Microsoft. Official source: https://github.com/microsoft/markitdown
