Check the -longname and -shortname attributs of [file]:Wonderful! Thank you for the fast help.
Does the (short) filename returned by tk_getOpenFile work to access the file?No, it doesn't work with the short version in Tcl.
Am 26.11.2025 um 17:26 schrieb Ralf Fassel:
Does the (short) filename returned by tk_getOpenFile work to accessNo, it doesn't work with the short version in Tcl.
the file?
Then, this is a bug.I don't have an example, but the process should be simple:
Do you have an example what exactly does not work ?
Am 27.11.2025 um 08:09 schrieb Harald Oehlmann:
Then, this is a bug.I don't have an example, but the process should be simple:
Do you have an example what exactly does not work ?
1. Create a long hierarchical directory structure that contains just
about 200 chars
2. Create in the deepest directory a file with more than 60 char. The extension of the file was in my case .Omega.
3. Retrieve the file path using tk_getOpenFile in a variable
4. Try to read the content of the file using that path. Alternativelly
check if the file exists.
Did you try this yourself? Because Windows does not let you go beyondWell, yes. Though my software.
the 256 character limit in a file path anyways.
It is known that Windows has a maximum path length of round about 260
chars for files and directories.
Interestigly Tcl can define files with longer paths and work with those without issues.
I discovered an issue though when using tk_getOpenFile to choose such a file. The function returns a path that is shortened by the OS by
replacing lots of chars in the path by ~.
I wonder if there is a way to get the original path back after using tk_getOpenFile.
Many thanks
Alex
Am 26.11.2025 um 17:15 schrieb meshparts:
It is known that Windows has a maximum path length of round about 260Ok, it's a mess!
chars for files and directories.
Interestigly Tcl can define files with longer paths and work with
those without issues.
I discovered an issue though when using tk_getOpenFile to choose such
a file. The function returns a path that is shortened by the OS by
replacing lots of chars in the path by ~.
I wonder if there is a way to get the original path back after using
tk_getOpenFile.
Many thanks
Alex
Now I get feedback from another customer, that tk_getOpenFile fails when special chars are involved in the file path name!
If I remove the -longpath option, it works again.
I need a solution for this.
Ok, it's a mess!
Now I get feedback from another customer, that tk_getOpenFile fails
when special chars are involved in the file path name!
If I remove the -longpath option, it works again.
I need a solution for this.
I looked deepr into the source code.
The "open" command fails when that path is converted into longname.
Other fi
Well, yes. Though my software.
The user can create folders in an integrated file explorer.
Then some processing is started and new folders and files are created automatically.
When the user then tries to select that long name file, the
tk_getOpenFile returns that short name instead.
When the software tries to read that file, it can't.
I have this temporary fix, that seem to work:
# Try to fix a path when file paths are longer than 260 chars which will force the OS to return short path names using ~
if {[string first ~ $path]>=0} {
set path [file attributes $path -longname]
}
So the fix is active only when the path is indeed too long.
It will probably fail if the path also contains special chars when
"open" is applied on this path.
On 12/1/2025 2:46 AM, meshparts wrote:
Well, yes. Though my software.
I am afraid I'm still confused. If the OS doesn't let you do it, how is
your software, running on that OS, able to do it?
The user can create folders in an integrated file explorer.
Then some processing is started and new folders and files are created
automatically.
So, you are creating a "logical" file hierarchy of sorts in your application.
When the user then tries to select that long name file, the
tk_getOpenFile returns that short name instead.
When the software tries to read that file, it can't.
OK, this now makes sense because your logical hierarchy doesn't nicely
map to the capabilities of the OS.
ust an FYI, the tilde (~) is an allowed character in Windows file andYes, I know.
folder names. It doesn't always mean "file path shortened by Windows".
* meshparts <alexandru.dadalau@meshparts.de>
| Am 02.12.2025 um 16:07 schrieb saito:
| > On 12/1/2025 2:46 AM, meshparts wrote:
| >
| >> Well, yes. Though my software.
| > I am afraid I'm still confused. If the OS doesn't let you do it, how
| > is your software, running on that OS, able to do it?
| Don't know. It somehow works.
| Probably because the folder path is shorter than 260 chars.
| When my aplication defines file in the folder, the file names are so
| long, that the total file path is larger than 260.
Probably it would be best if you could show that part of your code where
you create the files (stripped down so that one can try it).
How many directory levels are involved? Many short-named subdirs, or
few long-named subdirs, or mix of both?
No matter how I try, I alway get an error when creating a too-long
filename, regardless where I try it (cmd.exe, Windows explorer, TCL).
I could create a >260 chars filename on Linux and then mount that share
to Windows, but since you say the files are created locally, I assume
that the file system is NTFS locally on Windows?
R'
I could create a >260 chars filename on Linux and then mount that shareThat's a yes.
to Windows, but since you say the files are created locally, I assume
that the file system is NTFS locally on Windows?
Many short-named subdirs, orThis is the kind of path that causes the bug:
few long-named subdirs, or mix of both?
Am 02.12.2025 um 20:26 schrieb Ralf Fassel:
Many short-named subdirs, orThis is the kind of path that causes the bug:
few long-named subdirs, or mix of both?
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...
* 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'
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
So no error accessing the file via short or long name...Well in my case it#s an error, like aready said.
I reproduced it on Tcl 8.6 and 9.0.Great! Thanks.
Ticket is here:
https://core.tcl-lang.org/tk/tktview/ e3e32831781381c0d84efc9ab8b185e024c41990
Thanks,
Harald
* meshparts <alexandru.dadalau@meshparts.de>Yes, I aware of this setting. But on my system it's deactivated HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled = 0
| 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'
* 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'
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,089 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 153:53:33 |
| Calls: | 13,921 |
| Calls today: | 2 |
| Files: | 187,021 |
| D/L today: |
3,760 files (944M bytes) |
| Messages: | 2,457,163 |