Button/em_command parameter like [P] from MRT

Here you can propose new features, make suggestions etc.

Moderators: sheep, Hacker, Stefan2, white

Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Button/em_command parameter like [P] from MRT

Post by *Fla$her »

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.
Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Re: Button/em_command parameter like [P] from MRT

Post by *Fla$her »

Bump for v.10
Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Re: Button/em_command parameter like [P] from MRT

Post by *Fla$her »

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
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...
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 40952
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Button/em_command parameter like [P] from MRT

Post by *ghisler(Author) »

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:
%Bbranch2
%B0branch2
%B1branch1
%B2dir2
%B-dir2
%B-0dir2
%B-1dir1
%B-2(empty string)
Author of Total Commander
http://www.ghisler.com
NotNull
Member
Member
Posts: 183
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Button/em_command parameter like [P] from MRT

Post by *NotNull »

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
A little less 'kludgy':

Code: Select all

@echo off & setlocal
 
  for %%X in (%~dp0.) do echo "%%~nxX"
  pause
BTW: There is a bug in your script. Try it in C:\folder : it will strip the last character of teh foldername.
Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Re: Button/em_command parameter like [P] from MRT

Post by *Fla$her »

ghisler(Author) wrote: 2021-04-21, 08:27 UTCDo you mean %P but only the last part?
Yes. [P] in MRT just about that.
ghisler(Author) wrote: 2021-04-21, 08:27 UTCIf yes, I would suggest the following implementation:
I would only be glad of such a variety! :)
What is the difference between Bt and B- ?

NotNull wrote:There is a bug in your script. Try it in C:\folder
In this case, no. %~dp0 always has a \ at the end and is needed to implement [P].
But in your version, there are definitely not enough quotation marks — "%~dp0.", as in names there can be =;,) and space.
NotNull
Member
Member
Posts: 183
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Button/em_command parameter like [P] from MRT

Post by *NotNull »

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 :)).
NotNull
Member
Member
Posts: 183
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Button/em_command parameter like [P] from MRT

Post by *NotNull »

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_
Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Re: Button/em_command parameter like [P] from MRT

Post by *Fla$her »

2NotNull
This topic isn't about bat-codes, much less calling them from the console.
Fla$her wrote: 2021-04-20, 21:53 UTCgetting the result without scripts.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 40952
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Button/em_command parameter like [P] from MRT

Post by *ghisler(Author) »

What is the difference between Bt and B- ?
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.

I have implemented it now and it will be in beta 7.
Author of Total Commander
http://www.ghisler.com
Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Re: Button/em_command parameter like [P] from MRT

Post by *Fla$her »

2ghisler(Author)
t = target, - = minus. Understood. Thanks.
I have implemented it now and it will be in beta 7.
Famously! Super! :D
I checked, everything is fine. Finally! Thanks a lot! :)

Eng. TOTALCMD.CHM doesn't have a description yet.
Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Re: Button/em_command parameter like [P] from MRT

Post by *Fla$her »

2ghisler(Author)
Can you add B+ ?
Source path: c:\dir1\dir2

%B+C:
%B+0C:
%B+1dir1
%B+2dir2
%B+3(empty string)
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 40952
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Button/em_command parameter like [P] from MRT

Post by *ghisler(Author) »

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
http://www.ghisler.com
Fla$her
Member
Member
Posts: 121
Joined: 2020-01-18, 04:03 UTC

Re: Button/em_command parameter like [P] from MRT

Post by *Fla$her »

The drive letter is needed first, since sometimes you need to do something with the disk of the current directory.

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.
User avatar
petermad
Power Member
Power Member
Posts: 10422
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Re: Button/em_command parameter like [P] from MRT

Post by *petermad »

Fla$her wrote: 2021-04-23, 10:19 UTC 2ghisler(Author)
Can you add B+ ?
Source path: c:\dir1\dir2

%B+C:
%B+0C:
%B+1dir1
%B+2dir2
%B+3(empty string)
Support++
License #524 (1994)
Danish Total Commander Translator
TC 10.00 b8 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (20H2) 64bit, 'Everything' 1.4.1.1005
TC 3.21b2 on Android 6 & 11
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply