# Split a 10,000-Line AI Chat Export into Numbered Markdown Files

> Point md_splitter.py at your chat export and it creates a timestamped folder with one numbered Markdown file per conversation, leaving the original untouched.

URL: https://thuyavan.netlify.app/scripts/markdown-file-splitter
Updated: 2026-10-07

## Problem
AI tools export entire chat history as one huge .md file. Importing it into Notion causes lag and makes it impossible to file answers into different projects.

## Solution
A regex-based script that splits the export on the "--- # You Asked:" delimiter into individual, zero-padded files inside a timestamped workspace.

## Result
A clean, segmented library of conversations that imports individually into Notion or any knowledge system.

## Input
- One large Markdown chat export (path set in INPUT_FILE)

## Output
- Timestamped folder YYYY-MM-DD_HH-MM-SS_<Filename> with 001.md, 002.md …

## Optional output
- Terminal summary: files created and folder location

## System flow
Chat export .md (10,000+ lines) -> Load & decode (UTF-8 → UTF-8-SIG fallback) -> Compiled regex (MULTILINE split pattern) -> Numbered files (001, 002, 010 …) -> Timestamped workspace (Original untouched)

## How it works
- **High-performance regex:** re.compile with MULTILINE finds the delimiter pattern near-instantly.
- **Dual-mode split:** SPLIT_AT_START decides whether the separator stays with the previous or next file.
- **Workspace per run:** Timestamped folders prevent overwrites between exports.
- **Robust file handling:** Windows path normalisation, encoding fallback and zero-padded names.

## Configuration
- `INPUT_FILE`: Full Windows path to the chat export.
- `SPLIT_PATTERN_END`: Text marking a new question (default "# You Asked:").
- `SPLIT_AT_START`: Boolean – where the separator line lands.

## How to run
Paste the export path into INPUT_FILE:

    # INPUT_FILE = r"C:\Path\chat_export.md"
Run it:

    python md_splitter.py

## Impact
- Dramatically lower Notion RAM usage with small pages.
- Faster OS search because answers live in individual files.
- Easy drag-and-drop of tutorials and snippets into project folders.
- The original export is never modified.

## FAQ
**Why is my large Markdown file slow in Notion?**
Single files with tens of thousands of lines use a lot of memory. Splitting into small pages keeps Notion responsive.

**How does the script decide where to split?**
A compiled multiline regex matches the delimiter (default "--- # You Asked:"). SPLIT_AT_START controls which file keeps the separator.

**Does it change my original export?**
No. Output goes to a new YYYY-MM-DD_HH-MM-SS folder.

