✅❓ Button/em_command parameter like [P] from MRT
Moderators: Hacker, petermad, Stefan2, white
✅❓ Button/em_command parameter like [P] from MRT
Often, when working with command utilities, it's necessary to get the name of the parent folder without a path.
We have to reinvent the wheel in bat/wsh codes. It's high time to change that.
ghisler(Author), please finally simplify the buttons for codes with this parameter.
Maybe like [d], [t], [G] too. But with less priority.
We have to reinvent the wheel in bat/wsh codes. It's high time to change that.
ghisler(Author), please finally simplify the buttons for codes with this parameter.
Maybe like [d], [t], [G] too. But with less priority.
Last edited by Fla$her on 2023-10-19, 01:16 UTC, edited 1 time in total.
Overquoting is evil! 👎
Re: Button/em_command parameter like [P] from MRT
As a demonstration, I want to give an example of kludge in a .bat:
It's too bad that we have to resort to such dirty solutions (workarounds) instead of immediately getting the result without scripts.
It's strange that no one supported...
Code: Select all
@echo off & setlocal enabledelayedexpansion
set "d=%~dp0"&for %%i in ("!d!..\") do set "d=!d:%%~pi=!"
echo %d:~2,-1%
pause>nul
It's strange that no one supported...
Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50390
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Button/em_command parameter like [P] from MRT
Do you mean %P but only the last part?
If yes, I would suggest the following implementation:
%B branch name: parent
%B0 branch name: same as %B
%B1 branch name: grandparent
%B2 branch name: two levels up, etc.
%Bt parent of target dir (no branch)
%Bt1 grandparent of target dir (no branch)
%Bt2 target dir, two levels up (no branch), etc.
%B-, %B-1, %B-2 etc.: do not use dirs from branch view, just from displayed path.
Example for the difference:
Source path: c:\dir1\dir2
File name: branch1\branch2\file.ext
Results:
If yes, I would suggest the following implementation:
%B branch name: parent
%B0 branch name: same as %B
%B1 branch name: grandparent
%B2 branch name: two levels up, etc.
%Bt parent of target dir (no branch)
%Bt1 grandparent of target dir (no branch)
%Bt2 target dir, two levels up (no branch), etc.
%B-, %B-1, %B-2 etc.: do not use dirs from branch view, just from displayed path.
Example for the difference:
Source path: c:\dir1\dir2
File name: branch1\branch2\file.ext
Results:
%B | branch2 |
%B0 | branch2 |
%B1 | branch1 |
%B2 | dir2 |
%B- | dir2 |
%B-0 | dir2 |
%B-1 | dir1 |
%B-2 | (empty string) |
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Button/em_command parameter like [P] from MRT
A little less 'kludgy':Fla$her wrote: 2021-04-20, 21:53 UTC As a demonstration, I want to give an example of kludge in a .bat:Code: Select all
@echo off & setlocal enabledelayedexpansion set "d=%~dp0"&for %%i in ("!d!..\") do set "d=!d:%%~pi=!" echo %d:~2,-1% pause>nul
Code: Select all
@echo off & setlocal
for %%X in (%~dp0.) do echo "%%~nxX"
pause
Re: Button/em_command parameter like [P] from MRT
Yes. [P] in MRT just about that.
I would only be glad of such a variety!

What is the difference between Bt and B- ?
In this case, no. %~dp0 always has a \ at the end and is needed to implement [P].NotNull wrote:There is a bug in your script. Try it in C:\folder
But in your version, there are definitely not enough quotation marks — "%~dp0.", as in names there can be =;,) and space.
Overquoting is evil! 👎
Re: Button/em_command parameter like [P] from MRT
Yeah, quotes ... I forget them all the time (this was untested; should have mentioned that. But if you can create your version, you will have no problem fixing that
).

Re: Button/em_command parameter like [P] from MRT
Forgot this:
Code: Select all
T:\Endwith_d>type parent.cmd
@echo off & setlocal enabledelayedexpansion
set "d=%~dp0"&for %%i in ("!d!..\") do set "d=!d:%%~pi=!"
echo %d:~2,-1%
pause>nul
T:\Endwith_d>parent.cmd
Endwith_
Re: Button/em_command parameter like [P] from MRT
2NotNull
This topic isn't about bat-codes, much less calling them from the console.
This topic isn't about bat-codes, much less calling them from the console.
Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50390
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Button/em_command parameter like [P] from MRT
Bt would be the target directory (from the other panel). B- would be the source directory, ignoring any branch view subdirectory of the file under the cursor.What is the difference between Bt and B- ?
I have implemented it now and it will be in beta 7.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Button/em_command parameter like [P] from MRT
2ghisler(Author)
t = target, - = minus. Understood. Thanks.
I checked, everything is fine. Finally! Thanks a lot!
Eng. TOTALCMD.CHM doesn't have a description yet.
t = target, - = minus. Understood. Thanks.
Famously! Super!I have implemented it now and it will be in beta 7.

I checked, everything is fine. Finally! Thanks a lot!

Eng. TOTALCMD.CHM doesn't have a description yet.
Overquoting is evil! 👎
Re: Button/em_command parameter like [P] from MRT
2ghisler(Author)
Can you add B+ ?
Source path: c:\dir1\dir2
Can you add B+ ?
Source path: c:\dir1\dir2
%B+ | C: |
%B+0 | C: |
%B+1 | dir1 |
%B+2 | dir2 |
%B+3 | (empty string) |
Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50390
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: Button/em_command parameter like [P] from MRT
I can add it, but should it really add the drive letter? Currently %B cuts the drive letter (or server name for UNC paths).
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: Button/em_command parameter like [P] from MRT
The drive letter is needed first, since sometimes you need to do something with the disk of the current directory.
Examples:
Examples:
wmic volume where DriveLetter='D:' set Label="Data Label" |
PortableWinCDEmu.exe /unmount D: |
OSFMount.exe -d -m D: |
HD_Speed.exe /r /d D: |
BadNTFS.exe /l D: |
etc. |
Overquoting is evil! 👎
Re: Button/em_command parameter like [P] from MRT
Support++Fla$her wrote: 2021-04-23, 10:19 UTC 2ghisler(Author)
Can you add B+ ?
Source path: c:\dir1\dir2
%B+ C: %B+0 C: %B+1 dir1 %B+2 dir2 %B+3 (empty string)
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