Internal file association - Using %p%o variables

English support forum

Moderators: sheep, Hacker, Stefan2, white

Post Reply
User avatar
aviasd
Junior Member
Junior Member
Posts: 66
Joined: 2013-07-02, 18:28 UTC
Location: Israel

Internal file association - Using %p%o variables

Post by *aviasd »

Hi

I'm trying to accomplish a simple thing - extracting a zip into containing folder with filename as folder name.

Trying to associate a verb, I saw you can only pass %1 to the program - in my case 7z x -o%1 %1.

Problem is that you cannot extract to a folder where the foldername is the same as an existing filename.

I saw there's no way to pass %P%O to internal associations...
cm_unpackfiles does not take any arguments
Is there a way to accomplish that without associating to a script (and without using a button) ?
A glance to the future: What will Total commander be like in 10 years from now?
Now: Tc 9.51 Final

User avatar
Hacker
Moderator
Moderator
Posts: 11721
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Internal file association - Using %p%o variables

Post by *Hacker »

aviasd,
If I understand correctly, the usual way is Alt-F9, Delete, Alt-S, Enter. Not sure if this is what you're looking for, though.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.

User avatar
aviasd
Junior Member
Junior Member
Posts: 66
Joined: 2013-07-02, 18:28 UTC
Location: Israel

Re: Internal file association - Using %p%o variables

Post by *aviasd »

Yeah, That's exactly the process I want to automate - too much typing for such an everyday scenario...
Right now I have button that does this on one click, but i was wondering how to do it with internal association so i can right click on a file and select extract to folder
A glance to the future: What will Total commander be like in 10 years from now?
Now: Tc 9.51 Final

User avatar
nsp
Power Member
Power Member
Posts: 1286
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Internal file association - Using %p%o variables

Post by *nsp »

aviasd wrote:
2020-04-28, 13:39 UTC
Yeah, That's exactly the process I want to automate - too much typing for such an everyday scenario...
Right now I have button that does this on one click, but i was wondering how to do it with internal association so i can right click on a file and select extract to folder
Internal association are like Windows association and unfortunately do not use TC command or fancy TC syntax... if you have 7Zip/Peazip/Winrar fully installed, you can already see in the Right Click <7zip> menu the extract you want.

If you do not want any button, you can make a user_command and then reuse it for a hotkey or an alias.
You can also use external editor technique using tcer f4minimenu ....
if you want to process many files at once, you can use TCBL with filtering but you will have to use a dedicated ini command with filtering which fall to dedicated script..

User avatar
aviasd
Junior Member
Junior Member
Posts: 66
Joined: 2013-07-02, 18:28 UTC
Location: Israel

Re: Internal file association - Using %p%o variables

Post by *aviasd »

Internal association are like Windows association and unfortunately do not use TC command or fancy TC syntax... if you have 7Zip/Peazip/Winrar fully installed, you can already see in the Right Click <7zip> menu the extract you want.
I'm using TC as portable on Pcs that are clean, And I don't want to leave traces of other programs
You can also use external editor technique using tcer f4minimenu ....
This one actually looked like a good option but it seems it doesn't accept any of TC's %P %N arguments as well... Or does it? Documentation doesn't show how...
if you want to process many files at once, you can use TCBL with filtering but you will have to use a dedicated ini command with filtering which fall to dedicated script..
Doesn't the use of TCBL require making a button/user_command as well?
If you do not want any button, you can make a user_command and then reuse it for a hotkey or an alias.
This seems like the best option (in case tcer doesn't support special arguments)

The reason I don't want a button is, I try to use the keyboard exclusively for actions I do all the time, and just pressing Shift+F10 and selecting that option seemed the most intuitive for me.(2-3 Keyboard presses)

Sorry if that sounds too picky..

Just for reference the command I need to run is: 7z x -y -o%P%O %P%N
A glance to the future: What will Total commander be like in 10 years from now?
Now: Tc 9.51 Final

User avatar
Stefan2
Power Member
Power Member
Posts: 2920
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Extract ZIP archive to folder with filename; em_ExtractToFolder UDC

Post by *Stefan2 »

>> Sorry if that sounds too picky..
Not at all 8)

aviasd wrote:
2020-04-28, 10:44 UTC
...
I'm trying to accomplish a simple thing - extracting a zip into containing folder with filename as folder name.
...
aviasd wrote:
2020-04-29, 07:56 UTC
...
....
If you do not want any button, you can make a user_command and then reuse it for a hotkey or an alias.
This seems like the best option (in case tcer doesn't support special arguments)
...
...
Just for reference the command I need to run is: 7z x -y -o%P%O %P%N

Example:


[em_ExtractToFolder]
; extracting a zip into folder with ZIP-filename as folder name.
; https://ghisler.ch/board/viewtopic.php?p=384429#p384429
;   Usage: 7za <command> [<switches>...] <archive_name>
;     x: eXtract files with full paths
;     -y: assume Yes on all queries
;     -o{Directory}: set Output directory
;   TC params:
;     %P source path\ (not need, TC works already in current active folder)
;     %O filename without extension (used for foldername)
;     %N filename
cmd="%Commander_Path%\TOOLs\PACKER\7za.exe"
param=x -y -o"%O" %N


; ; Note: %O needs to be quoted if archive name contains white space,
; ; %N must not, as TC do this itself. Use an leading '?' as parameter to explore that by yourself.



FAQs: User-Defined Command (UDC) (usercmd.ini) em_command
- Create own commands to use in button or to execute them by an keyboard shortcut.

https://ghisler.ch/board/viewtopic.php?p=344777#p344777



HTH? :D 

User avatar
petermad
Power Member
Power Member
Posts: 9651
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, Denmark
Contact:

Re: Internal file association - Using %p%o variables

Post by *petermad »

2aviasd
Why not just assign a keybord shortcut to an em_command:

In your usercmd.ini file put:
[em_unzip]
cmd="pathto7zip\7z.exe"
param=x -y -o"%P%O" %P%N

and then via "Options..." -> "Misc" -> "Redefine hotkeys (keyboad remapping)" assign a hotkey to em_unzip
License #524
Danish Total Commander Translator
TC 9.51 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1909) 64bit, 'Everything' 1.4.1.965 (x64)
TC 3.0 on Android 6.0
Get:
Extended Total Commander Menus | TC Languagebar | TC Dark Help | PHSM-Calendar

User avatar
aviasd
Junior Member
Junior Member
Posts: 66
Joined: 2013-07-02, 18:28 UTC
Location: Israel

Re: Internal file association - Using %p%o variables

Post by *aviasd »

Thanks Guys,
By the time I read the post I already implemented my own alias: ex to a em_extractToFolder , which looks about the same as your editions, Although not as documented Stefan :wink:

But I did not give up on internal associations and created a script which I can use with internal associations variable %1.
I'm posting this as a template. Maybe it'll help someone.

Code: Select all

@echo off

::unQuoted filename
set filename=%~1
::Absolute Path
set abpath=%~f1
::Folder
set folderpath=%~dp1
::w/o ending backslash
set folderpath=%folderpath:~0,-1%

::parent folder name
call :getfoldername %folderpath%

::Just filename (no ext)
set jfilename=%~n1
::extension
set ext=%~x1
::size
set size=%~z1

goto run

:getfoldername
set foldername=%~n1
goto :EOF

:run
::run what's needed here
set output=%folderpath%\%jfilename%
if exist "%output%" set output=%output%.%random%

echo Executing.
7za x -y -o"%output%" "%filename%"
if %errorlevel% NEQ 0 pause
echo Done.

goto :EOF

A glance to the future: What will Total commander be like in 10 years from now?
Now: Tc 9.51 Final

Post Reply