Can I create a button/hotkey for immediate packing?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Can I create a button/hotkey for immediate packing?

Post by *avada »

Hi!

How could I do something like this:
Create a button and/or a hotkey, which when pressed/clicked would compress the selected files in the same folder (or an arbitrary one, or the folder in the other panel ) in a specific archive format.

It would be even better if I could use different compression settings as in the packer window, but for the button/hotkey specifically.

(A long time ago somone told me how to define a hotkey to compress in the same folder but, I've forgotten how.)
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

I'm lost...
I can't even figure out how the old hotkey works.
I only see "cm_PackFiles" set for it. Yet somehow it the compress windows shows up with the active directory...
Windows 10
User avatar
tuska
Power Member
Power Member
Posts: 3760
Joined: 2007-05-21, 12:17 UTC

Post by *tuska »

With CTRL + Click on the button ("cm_PackFiles") you can compress in the same folder.

Regards
Karl
Gruß,
Karl
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

I tried a achieving it by using an external exe. This is as far as I got so far:

Code: Select all

TOTALCMD#BAR#DATA
%commander_path%\plugins\Total7zip\7zg.exe
a "%O.zip" %P%S
wcmicons.dll,34



-1
I used 7zg.exe because it seems to do the same thing only it doesn't show the command line window.
It's mostly what I want. It'll always have the name of the first file though. I see no way of recreating the behavior of the packer in giving the folder's name instead when selecting multiple files. Which is quite a blow, because it's useful many times. I guess I can't use the same thing as a hotkey?
tuska wrote:With CTRL + Click on the button ("cm_PackFiles") you can compress in the same folder.

Regards
Karl
That's good to know. But I still don't how the shortcut does it. Based on that I would have gotten one step forward. I found shortcuts faster/better for common tasks anyway.
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1013
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Here's a PowerShell script you might find useful:

Code: Select all

<#

Save as TC_Packer.ps1
Put 7zg.exe and 7z.dll in the script folder
Call from TC with adjusted path:

Command:
powershell.exe

Parameter:
-NonInteractive -NoLogo -WindowStyle hidden -NoProfile -ExecutionPolicy remotesigned -Command "&{&'C:\PathToScript\TC_Packer.ps1' -FileList '%L' -SourceFolder '%P' -DestFolder '%T' -PackToSource}"

Check "Run minimized"

Remove -PackToSource to create the archive in the destination panel

#>

param(    
    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]$FileList,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]$SourceFolder,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]$DestFolder,

    [switch]$PackToSource
)

$exe7zip = "$PSScriptRoot\7zg.exe"

[array]$filePaths = Get-Content -Path $FileList

if ($PackToSource)
{
    $destArchive = $SourceFolder
}
else
{
    $destArchive = $DestFolder
}

if ($filePaths.count -eq 1)
{
    $fileNameNoExt = $(Get-Item -Path $filePaths[0]).BaseName
    $args7zip = "a `"$destArchive$fileNameNoExt.zip`" @`"$FileList`""
}
else
{
    $SourceFolderName = Split-Path -Leaf -Path $SourceFolder
    $args7zip = "a `"$destArchive$SourceFolderName.zip`" @`"$FileList`""
}

Start-Process -FilePath $exe7zip -ArgumentList $args7zip
avada
Senior Member
Senior Member
Posts: 217
Joined: 2007-10-05, 06:24 UTC

Post by *avada »

Thanks I'll check it out.
Windows 10
User avatar
Damel
Member
Member
Posts: 130
Joined: 2003-02-06, 01:11 UTC
Location: Prague, Czech Republic

Post by *Damel »

Nice script, but it does not work for cyrillic. :(
The best solution:
1. format C:
2. install TotalCmd
3. install Windows (optionally)
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1013
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Works here with this test file:

Code: Select all

File1_БЖ.txt
TC 8.52a x86, Win10 x64 Ger/Eng

Could you give me some more details?
User avatar
Damel
Member
Member
Posts: 130
Joined: 2003-02-06, 01:11 UTC
Location: Prague, Czech Republic

Post by *Damel »

Try pack file Морозко.txt in dir Морозко.
And then try Mrazík.txt in dir Mrazík.
Different alphabet, different behavior, different error.
The best solution:
1. format C:
2. install TotalCmd
3. install Windows (optionally)
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1013
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Now I could reproduce it.

Change the parameter from

Code: Select all

 ...  -FileList '%L'  ...
to

Code: Select all

 ...  -FileList '%UL'  ...
User avatar
Damel
Member
Member
Posts: 130
Joined: 2003-02-06, 01:11 UTC
Location: Prague, Czech Republic

Post by *Damel »

Good progress! Bud try pack file Морозко [1964] - Mrazík.txt.
The [ make problems here.
The best solution:
1. format C:
2. install TotalCmd
3. install Windows (optionally)
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1013
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Hmm I can edit my first post for some reason...

This should work:

Code: Select all

<#

Save as TC_Packer.ps1
Put 7zg.exe and 7z.dll in the script folder
Call from TC with adjusted path:

Command:
powershell.exe

Parameter:
-NonInteractive -NoLogo -WindowStyle hidden -NoProfile -ExecutionPolicy remotesigned -Command "&{&'C:\PathToScript\TC_Packer.ps1' -FileList '%UL' -SourceFolder '%P' -DestFolder '%T' -PackToSource}"

Check "Run minimized"

Remove -PackToSource to create the archive in the destination panel

#>

param(
    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]$FileList,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]$SourceFolder,

    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]$DestFolder,

    [switch]$PackToSource
)

$exe7zip = "$PSScriptRoot\7zg.exe"

[array]$filePaths = Get-Content -Path $FileList

if ($PackToSource)
{
    $destArchive = $SourceFolder
}
else
{
    $destArchive = $DestFolder
}

if ($filePaths.count -eq 1)
{
    $fileNameNoExt = $(Get-Item -LiteralPath $filePaths[0]).BaseName
    $args7zip = "a `"$destArchive$fileNameNoExt.zip`" @`"$FileList`""
}
else
{
    $SourceFolderName = Split-Path -Leaf -Path $SourceFolder
    $args7zip = "a `"$destArchive$SourceFolderName.zip`" @`"$FileList`""
}

Start-Process -FilePath $exe7zip -ArgumentList $args7zip
User avatar
Damel
Member
Member
Posts: 130
Joined: 2003-02-06, 01:11 UTC
Location: Prague, Czech Republic

Post by *Damel »

Now it works. Good job!
Thanks
The best solution:
1. format C:
2. install TotalCmd
3. install Windows (optionally)
Post Reply