Version 23 of file link

Updated 2011-07-03 10:48:36 by dkf
file link ?-linktype? linkname ?target?

(where -linktype is either -symbolic or -hard)

If only one argument is given, that argument is assumed to be linkName, and this command returns the value of the link given by linkName (i.e. the name of the file it points to). If linkName isn't a link or its value cannot be read (as, for example, seems to be the case with hard links, which look just like ordinary files), then an error is returned. If 2 arguments are given, then these are assumed to be linkName and target. If linkName already exists, or if target doesn't exist, an error will be returned. Otherwise, Tcl creates a new link called linkName which points to the existing filesystem object at target, where the type of the link is platform-specific (on Unix a symbolic link will be the default). This is useful for the case where the user wishes to create a link in a cross-platform way, and doesn't care what type of link is created. If the user wishes to make a link of a specific type only, (and signal an error if for some reason that is not possible), then the optional -linktype argument should be given. Accepted values for -linktype are "-symbolic" and "-hard". When creating links on filesystems that either do not support any links, or do not support the specific type requested, an error message will be returned. In particular Windows 95, 98 and ME do not support any links at present, but most Unix platforms support both symbolic and hard links (the latter for files only), MacOS supports symbolic links and Windows NT/2000/XP (on NTFS drives) support symbolic directory links and hard file links.


On Windows NT/XP (NTFS filesystem) this can be used to create symbolic directory links (a little known feature of Windows) or hard file links (an almost as little known feature of Windows).


Tcl 8.4a5 now supports this command.


Purpose: to discuss the possibility of adding a new 'file link' command to Tcl. (see http://groups.google.com/groups?hl=en&lr=&ie=UTF8&oe=UTF8&th=887b11ac0fab6e29&rnum=4 )


older stuff...

On MacOS, links are also supported (often called 'aliases'), but we need a patch like the one above to allow links to be created (i.e. the TclpObjLink function in tclMacFile.c needs completing).

Windows 95/98/ME etc don't support links very much at all, but Windows NT/2000/XP using the NTFS filesystem (version 5, I think), do! See http://www.hlm.inc.ru/ for creating file-links, and http://www.rekenwonder.com/linkmagic.htm , http://windows.oreilly.com/news/win2kcommands_0401.html#linkd , http://www.codeproject.com/w2k/junctionpoints.asp , http://www.sysinternals.com/ntw2k/source/misc.shtml#junction for directory-links (the last two contain source code to create and query such links).

DKF - You could handle the 95/98 case by simply reporting that the OS/FS doesn't support links (IIRC, supposedly not all Unix FSes support links either, though I've never encountered one which had problems that wasn't a mount of something derived from CP/M,DOS,etc...) If only shortcuts weren't the work of the devil incarnate after more than a few beers!

Vince - Indeed, in Tcl 8.3 'file readlink' of course just returns 'invalid argument' under all versions of Windows. I've now uploaded a version of the patch to the sourceforge link above which contains an implementation for unix and windows.


RM The "file link" command can not create relative links:

 sh>> ln -s ./a ./b

is different to

 tclsh>> file link -symbolic ./b ./a

The complete path can be a problem on mounted filesystems.

Vince adds that this has been addressed in Tcl 8.5.


LEG wants a -force option to forcibly create symbolic links with non-existing targets. This is e.g. needed when moving directory trees around, or when symbolic links are abused as information placeholders like it is done with the fnord webserver.

mjs agrees, the requirement that the target exist for a symbolic link is an arbitrary (and bad) choice. Perhaps the option should be -nocomplain to be consistent with e.g. glob?


LVwikignome - 2010-04-28 08:44:41

When you feel the topic is clear enough, the way to get the change considered is to request a TIP (Tcl Improvement Proposal) for the change. I'd recommend recruiting a champion from the TCT (Tcl Core Team) to help you through the process. Also, if you are uncertain about your ability to add the code for this change, you might recruit a Tcl C developer to look over your shoulder and help.

Good luck - it sounds like a useful change.