• Re: Handling of long paths in Tcl and Windows 11

    From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Fri Dec 5 10:58:50 2025
    From Newsgroup: comp.lang.tcl

    Am 02.12.2025 um 22:35 schrieb meshparts:
    Am 02.12.2025 um 20:26 schrieb Ralf Fassel:
    Many short-named subdirs, or
    few long-named subdirs, or mix of both?
    This is the kind of path that causes the bug:

    Folder structure:

    C:/Data/1234567/99_Meshparts/Meshparts-Offline/Assemblies/1234567/ Maschinen/12345678/Konzeptstudien/Varainte 3 Y-RIchtung 2040/250807-1234-Konzept_Palette_in_Y- Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/

    File name in that folder:

    250807-1234-Konzept_Palette_in_Y- Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed.Omega

    My app creates this file with:

      set code [catch {set fid [open $path w]} err]

    Then tries to read the content of the file with:

      set code [catch {set fid [open $path r]} err]

    The result is:

    couldn't open "C:/Data/1234567/99_MES~1/MESHPA~1/ASSEMB~1/1234567/ MASCHI~1/12345678/KONZEP~1/VARAIN~1/250807~1/250807~1.Omega": no such
    file or directory

    I just realized, that the file can be created because in that case the
    app uses the long file name.

    The issue is when the user selects the file using tk_getOpenFile which
    will return the short name.

    Should be easy to reproduce...

    We need a Tk ticket for this, as the initial issue it tk_getFile.
    I may take care.
    Give me some time...

    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Dec 5 16:36:43 2025
    From Newsgroup: comp.lang.tcl

    * meshparts <alexandru.dadalau@meshparts.de>
    | Am 02.12.2025 um 20:26 schrieb Ralf Fassel:
    | > Many short-named subdirs, or
    | > few long-named subdirs, or mix of both?
    | This is the kind of path that causes the bug:

    | Folder structure:

    | C:/Data/1234567/99_Meshparts/Meshparts-Offline/Assemblies/1234567/Maschinen/12345678/Konzeptstudien/Varainte
    | 3 Y-RIchtung
    | 2040/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/

    | File name in that folder:

    | 250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed.Omega

    | My app creates this file with:

    | set code [catch {set fid [open $path w]} err]

    | Then tries to read the content of the file with:

    | set code [catch {set fid [open $path r]} err]

    | The result is:

    | couldn't open
    | "C:/Data/1234567/99_MES~1/MESHPA~1/ASSEMB~1/1234567/MASCHI~1/12345678/KONZEP~1/VARAIN~1/250807~1/250807~1.Omega":
    | no such file or directory

    | I just realized, that the file can be created because in that case the
    | app uses the long file name.

    | The issue is when the user selects the file using tk_getOpenFile which
    | will return the short name.

    | Should be easy to reproduce...

    Duh... In my case it works in TCL/wish 8.6.17 / Windows 11:

    set dir "C:/Data/1234567/99_Meshparts/Meshparts-Offline/Assemblies/1234567/Maschinen/12345678/Konzeptstudien/Varainte 3 Y-RIchtung 2040/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/"

    file mkdir $dir

    cd $dir

    set file "250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed.Omega"

    set path [file join $dir $file]

    set code [catch {set fid [open $path w]} err]
    => code 0

    set code [catch {set fid [open $path r]} err]
    => code 0

    set sfile [tk_getOpenFile]
    C:/Data/1234567/99_MES~1/MESHPA~1/ASSEMB~1/1234567/MASCHI~1/12345678/KONZEP~1/VARAIN~2/250807~1/250807~1.OME

    set code [catch {set fid [open $sfile r]} err]
    => code 0

    file attrib $sfile -longname
    C:/Data/1234567/99_Meshparts/Meshparts-Offline/Assemblies/1234567/Maschinen/12345678/Konzeptstudien/Varainte 3 Y-RIchtung 2040/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed.Omega

    string equal $path [file attrib $sfile -longname]
    => 1

    So no error accessing the file via short or long name...

    Interestingly when trying to remove the directory from msys shell:

    $ rm -rf /c/data
    rm: cannot lstat `/c/data/1234567/99_Meshparts/Meshparts-Offline/Assemblies/1234567/Maschinen/12345678/Konzeptstudien/Varainte 3 Y-RIchtung 2040/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed.Omega': File or path name too long

    Windows explorer can remove the directory hierarchy without problems.

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Dec 5 16:39:47 2025
    From Newsgroup: comp.lang.tcl

    * Ralf Fassel <ralfixx@gmx.de>
    | set dir
    | "C:/Data/1234567/99_Meshparts/Meshparts-Offline/Assemblies/1234567/Maschinen/12345678/Konzeptstudien/Varainte
    | 3 Y-RIchtung
    | 2040/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/"

    Something messed up the line breaks in my posting, this is all one
    single line, with single spaces where there are newlines in the "".

    ../Varainte 3 Y-RIchtung 2040/...

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Fri Dec 5 17:08:04 2025
    From Newsgroup: comp.lang.tcl

    Am 05.12.2025 um 16:39 schrieb Ralf Fassel:
    * Ralf Fassel <ralfixx@gmx.de>
    | set dir
    | "C:/Data/1234567/99_Meshparts/Meshparts-Offline/Assemblies/1234567/Maschinen/12345678/Konzeptstudien/Varainte
    | 3 Y-RIchtung
    | 2040/250807-1234-Konzept_Palette_in_Y-Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/"

    Something messed up the line breaks in my posting, this is all one
    single line, with single spaces where there are newlines in the "".

    ../Varainte 3 Y-RIchtung 2040/...

    R'

    Thanks, Ralf, I appreciate.
    I remember, that this story is constantly handled.

    Aparently, TCL is good and accepts the long and short file.

    Due to that, the tk_getOpenFile may directly return the long file name.

    Thanks for testing,
    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Fri Dec 5 17:27:13 2025
    From Newsgroup: comp.lang.tcl

    Am 05.12.2025 um 17:08 schrieb Harald Oehlmann:
    Am 05.12.2025 um 16:39 schrieb Ralf Fassel:
    * Ralf Fassel <ralfixx@gmx.de>
    |     set dir
    |     "C:/Data/1234567/99_Meshparts/Meshparts-Offline/
    Assemblies/1234567/Maschinen/12345678/Konzeptstudien/Varainte
    |     3 Y-RIchtung
    |     2040/250807-1234-Konzept_Palette_in_Y-
    Richtung_V2_Modal_Traeger_F600mm_Y0_all_closed_msup/"

    Something messed up the line breaks in my posting, this is all one
    single line, with single spaces where there are newlines in the "".

          ../Varainte 3 Y-RIchtung 2040/...

    R'

    Thanks, Ralf, I appreciate.
    I remember, that this story is constantly handled.

    Aparently, TCL is good and accepts the long and short file.

    Due to that, the tk_getOpenFile may directly return the long file name.

    Thanks for testing,
    Harald

    I reproduced it on Tcl 8.6 and 9.0.

    Ticket is here:

    https://core.tcl-lang.org/tk/tktview/e3e32831781381c0d84efc9ab8b185e024c41990

    Thanks,
    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From meshparts@alexandru.dadalau@meshparts.de to comp.lang.tcl on Fri Dec 5 18:59:41 2025
    From Newsgroup: comp.lang.tcl

    Am 05.12.2025 um 16:36 schrieb Ralf Fassel:
    So no error accessing the file via short or long name...
    Well in my case it#s an error, like aready said.
    But maybe it's somehow related to Tcl 9 then...
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From meshparts@alexandru.dadalau@meshparts.de to comp.lang.tcl on Fri Dec 5 19:00:59 2025
    From Newsgroup: comp.lang.tcl

    Am 05.12.2025 um 17:27 schrieb Harald Oehlmann:
    I reproduced it on Tcl 8.6 and 9.0.

    Ticket is here:

    https://core.tcl-lang.org/tk/tktview/ e3e32831781381c0d84efc9ab8b185e024c41990

    Thanks,
    Harald
    Great! Thanks.
    Even if my bug could not be reproduced, it will help when fixed..
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Mon Dec 8 11:25:53 2025
    From Newsgroup: comp.lang.tcl

    * meshparts <alexandru.dadalau@meshparts.de>
    | Am 05.12.2025 um 16:36 schrieb Ralf Fassel:
    | > So no error accessing the file via short or long name...
    | Well in my case it#s an error, like aready said.
    | But maybe it's somehow related to Tcl 9 then...

    This site on MSDN has more on the topic:

    https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry

    It seems there are numerous ways to avoid the 260-char-length limit,
    depending on the API in use, the registry (and maybe also the phase of
    the moon, as usual on Windows ;-)

    NB. The registry value mentioned in the article is "0" on my Windows machine.

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From meshparts@alexandru.dadalau@meshparts.de to comp.lang.tcl on Mon Dec 8 14:56:07 2025
    From Newsgroup: comp.lang.tcl

    Am 08.12.2025 um 11:25 schrieb Ralf Fassel:
    * meshparts <alexandru.dadalau@meshparts.de>
    | Am 05.12.2025 um 16:36 schrieb Ralf Fassel:
    | > So no error accessing the file via short or long name...
    | Well in my case it#s an error, like aready said.
    | But maybe it's somehow related to Tcl 9 then...

    This site on MSDN has more on the topic:

    https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry

    It seems there are numerous ways to avoid the 260-char-length limit, depending on the API in use, the registry (and maybe also the phase of
    the moon, as usual on Windows ;-)

    NB. The registry value mentioned in the article is "0" on my Windows machine.

    R'
    Yes, I aware of this setting. But on my system it's deactivated HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled = 0
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Mon Dec 8 15:11:57 2025
    From Newsgroup: comp.lang.tcl

    * meshparts <alexandru.dadalau@meshparts.de>
    | Am 08.12.2025 um 11:25 schrieb Ralf Fassel:
    | > * meshparts <alexandru.dadalau@meshparts.de>
    | > | Am 05.12.2025 um 16:36 schrieb Ralf Fassel:
    | > | > So no error accessing the file via short or long name...
    | > | Well in my case it#s an error, like aready said.
    | > | But maybe it's somehow related to Tcl 9 then...
    | > This site on MSDN has more on the topic:
    | > https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
    | > It seems there are numerous ways to avoid the 260-char-length limit,
    | > depending on the API in use, the registry (and maybe also the phase of
    | > the moon, as usual on Windows ;-)
    | > NB. The registry value mentioned in the article is "0" on my Windows
    | > machine.
    | > R'
    | Yes, I aware of this setting. But on my system it's deactivated
    | HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
    | LongPathsEnabled = 0

    Since the registry alone would not help - the app also needs to opt-in
    via the .exe manifest - I think this is rarely used (?).

    Plus from looking at the source, TCL seems to go the "\\?\" prefix way
    for long file names anyway (cf. TclNativeCreateNativeRep() in win/tclWinFile.c), which works without registry fiddling:

    /*
    * If there is no "\\?\" prefix but there is a drive or UNC path prefix
    * and the path is larger than MAX_PATH chars, no Win32 API function can
    * handle that unless it is prefixed with the extended path prefix. See:
    * <https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maxpath>
    */
    [code that adds the \\?\ prefix for long pathnames > PATH_MAX]

    I *think* this means that if tk_getOpenFile returns a long path, TCL
    itself would probably handle it ok, but any other application which is
    passed that filename would fail if it does not go the same path
    (no pun intended :-).

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Mon Dec 8 15:55:52 2025
    From Newsgroup: comp.lang.tcl

    Am 08.12.2025 um 15:11 schrieb Ralf Fassel:
    * meshparts <alexandru.dadalau@meshparts.de>
    | Am 08.12.2025 um 11:25 schrieb Ralf Fassel:
    | > * meshparts <alexandru.dadalau@meshparts.de>
    | > | Am 05.12.2025 um 16:36 schrieb Ralf Fassel:
    | > | > So no error accessing the file via short or long name...
    | > | Well in my case it#s an error, like aready said.
    | > | But maybe it's somehow related to Tcl 9 then...
    | > This site on MSDN has more on the topic:
    | > https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
    | > It seems there are numerous ways to avoid the 260-char-length limit,
    | > depending on the API in use, the registry (and maybe also the phase of
    | > the moon, as usual on Windows ;-)
    | > NB. The registry value mentioned in the article is "0" on my Windows
    | > machine.
    | > R'
    | Yes, I aware of this setting. But on my system it's deactivated
    | HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
    | LongPathsEnabled = 0

    Since the registry alone would not help - the app also needs to opt-in
    via the .exe manifest - I think this is rarely used (?).

    Plus from looking at the source, TCL seems to go the "\\?\" prefix way
    for long file names anyway (cf. TclNativeCreateNativeRep() in win/tclWinFile.c), which works without registry fiddling:

    /*
    * If there is no "\\?\" prefix but there is a drive or UNC path prefix
    * and the path is larger than MAX_PATH chars, no Win32 API function can
    * handle that unless it is prefixed with the extended path prefix. See:
    * <https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maxpath>
    */
    [code that adds the \\?\ prefix for long pathnames > PATH_MAX]

    I *think* this means that if tk_getOpenFile returns a long path, TCL
    itself would probably handle it ok, but any other application which is
    passed that filename would fail if it does not go the same path
    (no pun intended :-).

    R'

    Please give me some time. The "long path" issues were all handled in the
    past in TCL. Probably, this part located in Tk was overlooked.
    There might be just an option necessary to the used system COM object.

    Thanks,
    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2