Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-17
10:51 • New ticket [076ed602e1] Windows: file delete -force on a tree deeper than MAX_... artifact: e168ed7b6d user: serhiy.storchaka
2025-12-18
11:15 • Ticket [bc7925fc50] Inconsistencies in long path handling in Tcl 8.6 and 9 s... artifact: 1f019c83f2 user: apnadkarni
11:10 • New ticket [bc7925fc50]. artifact: a7301d5b4f user: apnadkarni

Inconsistencies in long path handling in Tcl 8.6 and 9

Openbc7925fc5038e49d114fb6bc0d6d8366f9be2f67Created 349 days agoUpdated 349 days ago
Descriptionmarkdown2025-12-18 11:10:06

(I'm working on adding support for long paths as available in newer Windows versions. The bugs below are only tangentially related as the new support does not use the \\?\ prefix.)

Tcl 9 (and 8.6) support for long file paths (> MAX_PATH characters) on Windows is inconsistent and unusable from applications. Consider

% set longPath [file join [pwd] {*}[lrepeat 4 [string repeat X 254]]]; string length $longPath
1044
% file mkdir $longPath
% file isdirectory $longPath
1

All that works, but leads to inconsistent behaviour like you can create the directory but not change to it

% cd $longPath
couldn't change working directory to "C:/src/tcltk/wip/tcl/win/XXX.....XX": file name too long

Or the directory exists but not its parent!

% file isdirectory [file join $longPath ..]
0
% file exists [file join $longPath ..]
0

Or discrepancies with commands like glob

% glob $longPath/*
couldn't read directory "C:/src/tcltk/wip/tcl/win/XXXX...XX/*": no such file or directory
% glob $longPath/../*

The first case should not be returning an error. The second case should be returning the leaf component.

The basic issue is that Tcl tries to handle Windows MAX_PATH limitations by prefixing \\?\ to file paths whose lengths exceed MAX_PATH. That causes the Win32 API's to bypass their normal processing of paths and pass it directly to the NT Object manager which accepts paths up to 32K (or thereabouts). The problem is that

  • semantics of the NT Object manager are different from the Win32 "normal" or portable path syntax (leading to the bugs with the parent directories like above)
  • Tcl does not do this "helpful" preprocessing for all code paths.
  • Not all Win32 API's that Tcl calls may support this "pass-through" syntax

The result is the inconsistent and confusing behavior as logged in the c.l.t. thread and Tk ticket.

My opinion is that Tcl should not try to fix up deficiencies in a system API (Win32 in this case) unless it can do a reasonably thorough job. It is better to raise an error than present a logically inconsistent interface to the user as illustrated in the above commands.

Referenced by1
  • e168ed7b6dNew ticket [076ed602e1] Windows: [file delete -force] on a tree deeper than MAX_PATH returns OK and deletes nothing. ticket2026-10-17 10:51:12
apnadkarnimarkdown2025-12-18 11:15:49

As a point of clarification, the apn-win-longpaths branch adds support for paths longer than MAX_PATH on systems that are configured to allow longer paths via Group Policy or registry settings. On such systems, relevant Win32 API's natively support longer file paths and the branch merely ensures Tcl itself does not limit path lengths through the use of static arrays.

In particular, it will not help on systems where long path support has not been enabled. On these systems the issues listed in the ticket will continue to exist.

Log in (anonymous is fine) to add a comment.