Page 1 of 1

How to make a link for a directory or file using TC?

Posted: 2009-11-30, 00:30 UTC
by cheming
I can use mklink.exe for it , is there a handy method to do this in the TC?

IC

Posted: 2009-11-30, 01:36 UTC
by Clo
2cheming

:) Hello !

• You can use the internal command cm_CreateShortcut OR 1004 for a button, menu item or keyboard shortcut.
- You can also define how the created *.lnk file will be named :
<wincmd.ini> [Configuration]
AppendLnk=Flag
• Link files (*.lnk) will be created as follows:
¤ 0: file.ext –> file.lnk
¤ 1: file.ext –> file.ext.lnk
:mrgreen: KR
Claude
Clo

Posted: 2009-11-30, 22:43 UTC
by karlchen
Hi, Claude.

I am afraid creating a Windows shortcut (cm_CreateShortcut or <Ctrl-Shift-F5>) is not equivalent to creating a symbolic link using mklink.
To the best of my kowledge, Total Commander natively has got no commands to create symbolic links, hardlinks and junctions. This is, however, what mklink does.

You may check out this somewhat confusing thread way back from 2006. Confusing, too, because there is a tendency of mixing hardlinks and symbolic links. How create symbolic link in TC6?.

Another one: (TIP) Creating symbolic links on NTFS

"File not found" when running 'mklink' DOS command. Do not miss the advice given on integrating mklink as a T.C. user defined command or on the NTFSLinks addon for T.C..
(Beware, NTFSLink may or may not be Unicode compliant, so it may or may not co-operate correctly with Total Commander 7.50a. Flint might know?!)

Kind regards,
Karl

Re: How to make a link for a directory or file using TC?

Posted: 2009-11-30, 22:51 UTC
by karlchen
Hello, cheming.
I can use mklink.exe for it , is there a handy method to do this in the TC?
mklink.exe? To the best of my knowledge, mklink is an internal command of cmd.exe available on recent Windows versions, i.e Vista and above.
On older Windows versions, you had to use linkd.exe and junction.exe instead.

Karl

Posted: 2009-12-01, 03:19 UTC
by Balderstrom
This is what I use for junctions under Win2K, it could fairly easily be adjusted for mklink instead.

2 Buttons in SubBar (on ButtonBar/ToolBar):
Junction CREATE
Command: cmd.exe /c mjunction.cmd -ln
Parameters: %T %S

Junction DELETE
Command: cmd.exe /c mjunction.cmd -d
Parameters: %T %S

Code: Select all

:: 
:: Command: mjunction.cmd
::
:: Usage1: Select Folders in (Source) Pane; Junctions created in Target Pane.
:: Usage2: Select Folders in (Source) Pane; Junctions deleted
::
@ECHO OFF
CLS

IF "%~1"=="-d" GOTO:DELETE_JUNCTION
:CREATE_JUNCTION
IF "%~3" == "" GOTO:EOF
junction "%~2%~3" "%~3"
SHIFT /3
GOTO:CREATE_JUNCTION

:DELETE_JUNCTION
IF "%~2" == "" GOTO:EOF
junction -d "%~2"
SHIFT /2
GOTO:DELETE_JUNCTION

Posted: 2009-12-01, 05:28 UTC
by MVV
BTW symlinks are new in Vista/7 and you need admin rights to create them. Also them have some not very useful features - e.g. if you have symlink you won't see real file/folder date, you will see only symlink date, size field also is not updated as I see.
So I suggest to create only junctions using /J command line switch for mklink command (note that in Vista/7 it is a command, not a separate executable, so you can't use it w/o cmd.exe).

Posted: 2009-12-01, 20:55 UTC
by sqa_wizard
2Balderstrom: You don't need a button at TC to delete a junction !
TC safely removes the junction to a folder (leaves the files untouched) by simply pressing DEL or F8 key :)

!!! Caution !!! Don't try it with Windows Explorer of an OS prior to Vista !
This will first delete the files and then remove the junction !

Posted: 2009-12-01, 21:40 UTC
by Balderstrom
@sga_wizard, TC may handle junctions correctly for deletion, and if so it's one of the few things it does do correctly with them.

The only reason to not delete junctions with Explorer is it will drop the junction into the Recycle-Bin, and when the Recycle-Bin is emptied: Windows parses the junction and deletes the real files in the real/actual directory.

Ghisler also refuses to allow us to disable the Annoying pop-up every time a file is deleted: Unless we use "Explorer Delete method" -- which then means junction deletions are no-longer safe.

TC's delete-confirmation-popup is also Exactly-the-same in it's phrasing whether or not the files will go to the Recycle bin or not. TC also does not distinguish between Shift+Del and normal Delete, the phrasing of the pop-up is exactly the same.

None of that behaviour is acceptable to me. My middle-mouse button for every other application is "Delete"; for TC I made it be: CTRL+Delete & I defined a user-command to call "Recycle.exe" for Ctrl+Del.

I don't get pop-ups for normal deletes any longer.
I do get pop-ups for SHIFT+Deletes (which do not go to the recycle bin).
And I delete junctions from the SubBar dropDown menu.

TC still doesn't handle junction move/copy how I believe it should. If I drag-move a junction from a current dir into a subFolder (same panel) or to the parent folder [..] then TC will move the junction. Yet if I drag-move a junction from one panel to the other, TC creates a folder and copies the contents of the junction. Thus I am forced to do a Windows Cut/Paste to move the junction.

As MVV noted here in regards to the new Symlinks Report broken reparse points after copying/moving,
The * junction bug I reported in 2005 wasn't fixed for 4 years (in one of the recent TC beta's or the 7.50 final)

*(1/ Drag/Move a junction: Explorer Moves the Junction; whereas TC would: Create a Folder, and MOVE all contents of Junction to the new folder.

The current fix is suboptimal as it is inconsistent behaviour whether you drag within a panel or to the other panel.

Posted: 2009-12-01, 22:05 UTC
by sqa_wizard
The current fix is suboptimal as it is inconsistent behaviour whether you drag within a panel or to the other panel.
Yes, I agree. It is time for a proper detection of junctions and use a individual handling, as junctions get used more and more since Vista and now Win7.