GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — shutil.rmtree() cannot remove directory trees deeper than MAX_PATH on Windows · Issue #159681 · python/cpython

shutil.rmtree() cannot remove directory trees deeper than MAX_PATH on Windows #159681

New issue
Copy link
New issue
Copy link
Open
Open
shutil.rmtree() cannot remove directory trees deeper than MAX_PATH on Windows#159681
Copy link
Assignees
serhiy-storchaka
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesOS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@serhiy-storchaka
serhiy-storchaka
opened on Oct 18, 2026
Issue body actions

On Windows, shutil.rmtree() uses the path-based implementation, which builds the full path of every file and directory. Unless long paths are enabled in the registry (LongPathsEnabled, off by default), paths longer than MAX_PATH (260 characters) cannot be accessed. os.walk() ignores the resulting FileNotFoundError, so the deep part of the tree is silently skipped, and rmtree() then fails with "The directory is not empty".

import os, shutil
path = '\\\\?\\' + os.path.abspath('deep')
os.mkdir(path)
for i in range(200):
    path += '\\d'
    os.mkdir(path)
shutil.rmtree('deep')
OSError: [WinError 145] The directory is not empty: 'deep\\d\\d\\d\\...'

Using extended-length paths (\\?\C:\...) will help, but as a side effect they can leak to the user via errors.

Linked PRs

  • gh-159681: Fix shutil.rmtree() for paths longer than MAX_PATH on Windows #159699

Activity

  1. serhiy-storchaka
    self-assigned this
    on Oct 18, 2026
  2. serhiy-storchaka
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    OS-windows
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on Oct 18, 2026
  3. kevinprimeraquecreo-stack
    added this to Project_VKand Project_VKon Oct 18, 2026
  4. github-project-automation
    moved this to Todo in Project_VKon Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @serhiy-storchaka
    serhiy-storchaka

Labels

3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesOS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.