Need help with custom command (mklink)
Moderators: Hacker, petermad, Stefan2, white
Need help with custom command (mklink)
Dear all,
New TC user here, I'm having trouble creating new command buttons, any help would be appreciated. The one that I'm currently having trouble with has to do with making junction links. If I open a cmd terminal and run "mklink testlink /J C:\myfolder", then this will create a junction link of "C:\myfolder" on the current path, named "testlink". However, if I create a button like this:
Image: https://i.imgur.com/2Nw4BAG.png
which I would assume that it creates a link of the target path onto the current one, I get instead the error:
Image: https://i.imgur.com/jX1dQ1o.png
Could somebody explain to me how to create a button that does what I want?
Thank you in advance.
New TC user here, I'm having trouble creating new command buttons, any help would be appreciated. The one that I'm currently having trouble with has to do with making junction links. If I open a cmd terminal and run "mklink testlink /J C:\myfolder", then this will create a junction link of "C:\myfolder" on the current path, named "testlink". However, if I create a button like this:
Image: https://i.imgur.com/2Nw4BAG.png
which I would assume that it creates a link of the target path onto the current one, I get instead the error:
Image: https://i.imgur.com/jX1dQ1o.png
Could somebody explain to me how to create a button that does what I want?
Thank you in advance.
Re: Need help with custom command (mklink)
Hi and welcome geo909
Please take a right click on your button, chose COPY and paste the button code in here.
Additionally you can take a search on the forum to find f.ex:
viewtopic.php?f=28&t=51775&p=357299&hilit=mklink#p357299
and some other examples.
c u later
Please take a right click on your button, chose COPY and paste the button code in here.
Additionally you can take a search on the forum to find f.ex:
viewtopic.php?f=28&t=51775&p=357299&hilit=mklink#p357299
and some other examples.
c u later
Re: Need help with custom command (mklink)
2geo909
Do you use 32-bit TC in 64-bit Windows?
Do you use 32-bit TC in 64-bit Windows?
Andrzej P. Wozniak
Polish subforum moderator
Polish subforum moderator
Re: Need help with custom command (mklink)
mklink is an internal CMD command, so there is no EXE which TC could launch. You must specify cmd.exe as application and mklink as the command to run by CMD. Example:To copy the button, mark the code above and paste it onto a free space on your button bar.
[EDIT] Typo [/EDIT]
Regards
Dalai
Code: Select all
TOTALCMD#BAR#DATA
cmd.exe
/c "mklink /J testlink %T"
C:\Windows\System32\cmd.exe
mklink
-1
[EDIT] Typo [/EDIT]
Regards
Dalai
Last edited by Dalai on 2019-08-28, 19:47 UTC, edited 1 time in total.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Re: Need help with custom command (mklink)
From Petermad's extended Menus for TC:
Fore full absolute fantastic menus see:
https://www.ghisler.ch/board/viewtopic.php?t=33740
Code: Select all
[em_ext_junction]
cmd=%COMSPEC% /K
param=if exist %P%N\* (mklink /J %T%N %P%N) else (echo The cursor must be on a FOLDER)
path=%SYSTEMDRIVE%\
menu=Make Junction in Opposite Panel to FOLDER Under Cursor (Not on Network)
button=%COMMANDER_EXE%,12
[em_ext_symlinkd]
cmd=*%COMSPEC% /K
param=if exist %P%N\* (mklink /D %T%N %P%N) else (echo The cursor must be on a FOLDER)
path=%SYSTEMDRIVE%\
menu=Make Symlink in Opposite Panel to FOLDER Under Cursor
button=%COMMANDER_EXE%,12
[em_ext_symlink]
cmd=*%COMSPEC% /K
param=if not exist %P%N\* (mklink %T%N %P%N) else (echo The cursor must be on a FILE)
path=%SYSTEMDRIVE%\
menu=Make Symlink in Opposite Panel to FILE Under Cursor
button=%COMMANDER_EXE%,12
[em_ext_hardlink]
cmd=%COMSPEC% /K
param=if not exist %P%N\* (mklink /H %T%N %P%N) else (echo The cursor must be on a FILE)
path=%SYSTEMDRIVE%\
menu=MAke Hardlink in Opposite Panel to FILE Under Cursor (Only on Same Drive)
button=%COMMANDER_EXE%,12
https://www.ghisler.ch/board/viewtopic.php?t=33740
Windows 11 Home, Version 24H2 (OS Build 26100.3915)
TC 11.51 x64 / x86
Everything 1.5.0.1391a (x64), Everything Toolbar 1.5.2.0, Listary Pro 6.3.2.88
QAP 11.6.4.2.1 x64
TC 11.51 x64 / x86
Everything 1.5.0.1391a (x64), Everything Toolbar 1.5.2.0, Listary Pro 6.3.2.88
QAP 11.6.4.2.1 x64
Re: Need help with custom command (mklink)
Thanks a lot guys! Dalai's suggestion works, I'll look into Horst.Epp's a bit more to understand what it does.
@usher: I'm using 64 bit windows
@Stefan2: Thanks for the suggestions, I'll have them in mind.
@usher: I'm using 64 bit windows
@Stefan2: Thanks for the suggestions, I'll have them in mind.
Re: Need help with custom command (mklink)
Add the em_commands into your usercmd.ini and you can use them in menus, buttons or assig Hotkeys to it.geo909 wrote: 2019-08-28, 15:59 UTC Thanks a lot guys! Dalai's suggestion works, I'll look into Horst.Epp's a bit more to understand what it does.
@usher: I'm using 64 bit windows
@Stefan2: Thanks for the suggestions, I'll have them in mind.
Windows 11 Home, Version 24H2 (OS Build 26100.3915)
TC 11.51 x64 / x86
Everything 1.5.0.1391a (x64), Everything Toolbar 1.5.2.0, Listary Pro 6.3.2.88
QAP 11.6.4.2.1 x64
TC 11.51 x64 / x86
Everything 1.5.0.1391a (x64), Everything Toolbar 1.5.2.0, Listary Pro 6.3.2.88
QAP 11.6.4.2.1 x64
Re: Need help with custom command (mklink)
geo909,
1. You can't use %-parameters in Command field, only in Parameters.
2. mklink is not a separate program, it is an internal command within cmd.exe.
That's why Dalai's button is correct.
BTW, you can use my NTLinks Maker tool if you need to create links often.
1. You can't use %-parameters in Command field, only in Parameters.
2. mklink is not a separate program, it is an internal command within cmd.exe.
That's why Dalai's button is correct.
BTW, you can use my NTLinks Maker tool if you need to create links often.
Re: Need help with custom command (mklink)
My question was about both TC and Windows bitness. In 64-bit Windows you should use 64-bit TC, otherwise some features (system commands, paths on disk, etc.) may be unavailable.
Andrzej P. Wozniak
Polish subforum moderator
Polish subforum moderator
Re: Need help with custom command (mklink)
2geo909
These are external commands that are meant to be used together with my Extended Menus (see signature), but they can of course alo be used for your own buttons and shortcuts. See: http://madsenworld.dk/tcmd/symlinkmenu.pngI'll look into Horst.Epp's a bit more to understand what it does
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Re: Need help with custom command (mklink)
I read comments above and wrote command for selected files.
you can pause operation if something goes wrong
Than I added it to %appdata%\GHISLER\usercmd.ini
Than Start -> Change Start Menu -> Add Item
Search in command field "em_ext_hardlink"
Shortcut Key = Ctrl+Alt+Shift+F5
And "Voila". I can create links without any side program or plugin.
Code: Select all
[em_ext_hardlink]
cmd=cmd /C
param=(for /d %%a in (%P%S) do mklink /H "%T%%~na%%~xa" %%a)
path=%SYSTEMDRIVE%\
menu=Make Hardlink in Opposite Panel to all selected files (Only on Same Drive)
button=%COMMANDER_EXE%,12
Code: Select all
param=(for /d %%a in (%P%S) do mklink /H "%T%%~na%%~xa" %%a||if not [%errorlevel%]==[0] pause)
Than Start -> Change Start Menu -> Add Item
Search in command field "em_ext_hardlink"
Shortcut Key = Ctrl+Alt+Shift+F5
And "Voila". I can create links without any side program or plugin.
Re: Need help with custom command (mklink)
23axarko
There's one important thing I don't understand. As far as I see the command iterates over directories and tries to create hardlinks to them. But hardlinks cannot point to directories (only to files).
PS: You can shorten to
One other thing: I strongly recommend to quote loop variables within a command, i.e. it's better to use instead of .
There's one important thing I don't understand. As far as I see the command iterates over directories and tries to create hardlinks to them. But hardlinks cannot point to directories (only to files).
PS: You can shorten
Code: Select all
%%~na%%~xa
Code: Select all
%%~nxa
Code: Select all
mklink ... "%%~a"
Code: Select all
mklink ... %%a
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Re: Need help with custom command (mklink)
2Dalai
Thanks for the advice.
Variable "%%a" will create two quotes for each side. Like ""audio_file.mka""
I tried to do the same using for /r, but it didn't work. I wasn't able to replace the quotation marks in the file names using a single line of code. However, even though /d is supposed to iterate through directories, it worked on files as well.
Thanks for the advice.
Variable "%%a" will create two quotes for each side. Like ""audio_file.mka""
I tried to do the same using for /r, but it didn't work. I wasn't able to replace the quotation marks in the file names using a single line of code. However, even though /d is supposed to iterate through directories, it worked on files as well.
Re: Need help with custom command (mklink)
Look more closely. I used "%%~a" instead of "%%a".3axarko wrote: 2024-11-20, 15:55 UTCVariable "%%a" will create two quotes for each side. Like ""audio_file.mka""
That's not what I'm seeing. Check out this code directly on a CMD:However, even though /d is supposed to iterate through directories, it worked on files as well.
Code: Select all
cd /D "%SystemRoot%\"
for /D %T IN (*.*) DO echo %T
But I think I know why it works for you. If you select only files in TC the parameter %P%S will be replaced with their names. But as soon as you select directories, the mklink command will throw an error. Not sure if it's intentional that the for loop behaves the same way with and without the /D switch in such cases. I still suggest to remove the /D switch as it is irritating to read such code which doesn't really make sense.
One more thing: Be aware that the command line has a length limit that is reached rather quickly if you use %P%S. It's much better to use a list file via %L or %WL instead. The for loop must be told to work with a file in that case, something like this:
Code: Select all
for /F "delims=" %%F IN ('type "%WL"') DO mklink ...
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Re: Need help with custom command (mklink)
I'm not sure I agree with that. AFAIK "For /F" has limited Unicode support, so if you don't change the codepage to UTF-8 first, you might run into trouble.Dalai wrote: 2024-11-20, 18:24 UTC It's much better to use a list file via %L or %WL instead. The for loop must be told to work with a file in that case, something like this:Code: Select all
for /F "delims=" %%F IN ('type "%WL"') DO mklink ...