# Fix "File name too long" (Errno 36) in yt-dlp

yt-dlp fails with 'unable to open for writing: [Errno 36] File name too long' when a title is a whole caption. Why --trim-filenames doesn't always fix it, the byte-limited output template that does, and a safe default for pipelines.

The video extracts fine, the format is picked, and then yt-dlp stops before writing a single byte. The cause is the file name, not the download: the title is too long for your file system. It mostly shows up on sites where the "title" is the whole post caption, and almost always in scripts and pipelines, because that's where nobody is looking at the titles.

## What the error looks like

```bash
[info] <id>: Downloading 1 format(s): <format>
ERROR: unable to open for writing: [Errno 36] File name too long: 'Полный текст подписи к ролику, который ... .mp4.part'
```

The giveaway is that metadata works. `yt-dlp --print title "URL"` succeeds on the same link, and `-j` returns the full JSON. Only the step that opens `<title>.<ext>.part` fails.

## Why it happens

yt-dlp's default output template is `%(title)s [%(id)s].%(ext)s`, and most scripts use `%(title)s.%(ext)s`. Both put the entire title in the file name.

On YouTube a title is capped at 100 characters, so that's rarely a problem. On Facebook reels, TikTok, X and Instagram, the title is often the post's whole caption, hashtags included. Linux file systems such as ext4 allow 255 **bytes** per file name, and bytes are the catch:

- Latin letters are 1 byte each in UTF-8.
- Cyrillic, Greek, Hebrew and Arabic letters are 2 bytes.
- Chinese, Japanese and Korean characters are 3 bytes, most emoji 4.

A 130-character Russian caption is already 260 bytes. That's why the error seems random: the same script works for months on English titles and then fails on the first long caption in another script.

## Fix: cut the title by bytes in the output template

yt-dlp's template syntax can truncate a field to a number of bytes with `.NB`:

```bash
yt-dlp -o "%(title).150B [%(id)s].%(ext)s" "URL"
```

`%(title).150B` keeps at most 150 bytes of the title and never splits a multi-byte character. 150 leaves room for the ` [id]`, the extension and the temporary suffixes yt-dlp adds while it works (`.part`, and `.f137`-style names when it merges video and audio). Keep the `[%(id)s]` so two posts with the same caption don't overwrite each other.

Check the name before you download anything:

```bash
yt-dlp --simulate --print filename -o "%(title).150B [%(id)s].%(ext)s" "URL"
```

In Python, it's the same template in `outtmpl`:

```python
import yt_dlp

opts = {"outtmpl": "%(title).150B [%(id)s].%(ext)s"}
with yt_dlp.YoutubeDL(opts) as ydl:
    ydl.download([url])
```

If you put the template in a [config file](/guides/yt-dlp-config-file), every run picks it up. The [output template guide](/guides/yt-dlp-output-template) covers the rest of the syntax.

## Why --trim-filenames isn't enough

`--trim-filenames N` looks like the obvious fix, and on English titles it works. But it counts **characters**, not bytes (its help text says so: "the specified number of characters"). We tested it on yt-dlp `2026.11.23` with a 200-character Cyrillic title:

| Command | Result |
| --- | --- |
| `-o "%(title)s.%(ext)s"` | Errno 36 |
| `--trim-filenames 150 -o "%(title)s.%(ext)s"` | Errno 36 (150 characters = 300 bytes) |
| `--trim-filenames 100 -o "%(title)s.%(ext)s"` | works, 204 bytes |
| `-o "%(title).150B.%(ext)s"` | works, 154 bytes |

So `--trim-filenames` only protects you if you size it for the worst script you'll ever see, which means about 80 characters for CJK text and fewer once emoji are involved. The byte cut doesn't need that guess. There's an open request to make it count bytes ([yt-dlp#12386](https://github.com/yt-dlp/yt-dlp/issues/12386), open since February 2025), but for now the template is the reliable fix.

## Don't reach for --restrict-filenames

`--restrict-filenames` keeps only ASCII. On a title written entirely in Cyrillic or Japanese, that leaves one underscore: the file is called `_.mp4`, and the next download with the same kind of title overwrites it. It's fine if all your sources are English and you want shell-safe names, but it isn't a fix for this error.

## Use the id when you don't need the title

If a program, not a person, reads your downloads, the safest name is the one that can't be too long:

```bash
yt-dlp -o "%(id)s.%(ext)s" --write-info-json "URL"
```

The id is short and unique per site, and `--write-info-json` keeps the full title, caption and everything else next to the file, so you lose nothing. Store the title in your database, not in the file name. [Getting video metadata](/guides/get-video-metadata) shows what's in that JSON.

## In a pipeline, also fail fast

On its own, Errno 36 isn't a network error, so retrying the same command gives the same result every time. If your job runner retries failed downloads, treat this error as permanent (or rerun once with the id-only template) instead of burning every attempt on it. More on keeping unattended runs healthy in [yt-dlp automation](/guides/yt-dlp-automation).

<DocCta variant="workflow" ctaVariant="filename-too-long-guide" />

<Faq />

## Related guides

- [yt-dlp output templates](/guides/yt-dlp-output-template)
- [Get video metadata with yt-dlp](/guides/get-video-metadata)
- [Batch download with yt-dlp](/guides/batch-download)
- [yt-dlp for Facebook](/guides/yt-dlp-for-facebook)
- [Fix common yt-dlp errors](/guides/fix-yt-dlp-errors)