Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-11-22
22:58 • Closed ticket [08203e40e3]: Windows: file delete -force fails on a directory c... artifact: 29fcdf14f1 user: jan.nijtmans
2026-10-31
19:46
Fix [08203e]: Windows: [file delete -force] failed on a directory containing a symbolic link check-in: 95b8eb73c5 user: jan.nijtmans tags: core-8-6-branch
19:16
Fix [08203e]: Windows: [file delete -force] failed on a directory containing a symbolic link check-in: a59fcaf470 user: jan.nijtmans tags: core-9-0-branch
2026-10-30
22:23
Fix [08203e]: Windows: [file delete -force] failed on a directory containing a symbolic link check-in: 6f1fbfbc88 user: jan.nijtmans tags: trunk, main
2026-10-20
18:11 • Ticket [08203e40e3] Windows: file delete -force fails on a directory containin... artifact: 1340e057a3 user: serhiy.storchaka
2026-10-17
14:27 • Ticket [08203e40e3]: 3 changes artifact: 9861d42209 user: serhiy.storchaka
14:26
Fix [08203e40e3]: on Windows, [file delete -force] failed with "invalid argument" on a directory con... closed check-in: d876873757 user: serhiy.storchaka tags: win-delete-tree-with-symlinks
10:51 • New ticket [08203e40e3] Windows: file delete -force fails on a directory conta... artifact: f5651f90c1 user: serhiy.storchaka

Windows: [file delete -force] fails on a directory containing a symlink

Closed / Fixed08203e40e341386c6dc5aac0b8405e506f658656Created 46 days agoUpdated 10 days ago
Descriptionwiki2026-10-17 10:51:12
On Windows, [file delete -force] fails on a directory that contains a file symbolic link. Tcl itself creates such links: [file link -symbolic] makes a real symlink for a file target since 8.6.11 ([548cd945d6]). This needs administrator rights or Developer Mode, the same as mklink.
file mkdir d
close [open d/a.txt w]
file link -symbolic d/b.txt d/a.txt   ;# or: mklink d\b.txt a.txt
file delete -force d

Actual: error deleting "...": invalid argument, and d stays. Expected: d is deleted. Deleting the link itself with [file delete d/b.txt] works.

Cause: TraverseWinTree() (win/tclWinFCmd.c) hands every reparse point to TraversalDelete() as DOTREE_LINK, which calls DoRemoveJustDirectory() and so TclWinSymLinkDelete() (win/tclWinFile.c). That function always passes IO_REPARSE_TAG_MOUNT_POINT to FSCTL_DELETE_REPARSE_POINT, which fails with a tag mismatch for a symlink (tag 0xA000000C), giving EINVAL. Even if the reparse data were removed, RemoveDirectoryW() cannot remove a file. A directory symlink inside the tree goes through the same code and probably fails the same way. The same function also explains [3c13c4ed31] ([file delete] on a directory symlink fails with "illegal operation on a directory"/"is a directory"), which was closed as Invalid. Possible fix: delete links with DeleteFileW() or RemoveDirectoryW() depending on FILE_ATTRIBUTE_DIRECTORY. Both remove the link and not its target.

Related: [972c35d41d] ([file copy] of symlinks), [c8d4f01a54] (NTFS symlinks not supported by [file]).

Seen on Windows 11 in 8.6.18, 9.0.5 and 9.1.

Referenced by1
  • d876873757Fix [08203e40e3]: on Windows, [file delete -force] failed with "invalid argument" on a directory containing a symbolic link to a file or a directory (only junctions worked). Remove links to files like files, and other links to directories with RemoveDirectoryW. check-in2026-10-17 14:26:58
serhiy.storchakawiki2026-10-17 14:27:36

Proposed fix in branch win-delete-tree-with-symlinks: a link to a file is removed like a file, and a link to a directory that is not a junction (mklink /D) with RemoveDirectoryW(); the targets are not touched. Directory symbolic links inside the tree failed the same way. Tests winFCmd-9.7 and 9.8 (need the right to create symbolic links).

serhiy.storchaka Ticket [08203e40e3]: 1 change [History diff]2026-10-20 18:11:29
jan.nijtmanswiki2026-11-22 22:58:12

Merged to [trunk], core-9-0-branch and core-8-6-branch

Many thanks!

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