Help! How to multicommand unpack?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Help! How to multicommand unpack?

Post by *gerappa »

Hello everyone!
How can i do the following (below) based on this script write in usercmd.ini

[em_ext_copyallnewdir]
cmd=%COMSPEC% /c
param=(if not exist "%T%O" md "%T%O") && (if not exist %P%N\ for %%i in (%P%S) do if not exist %%i\ copy %%i "%T%O\")
menu=Copy marked files to directory with name under cursor to opposite panel
button=%COMMANDER_PATH%\wcmicons.dll,29

i would like basicaly the same with some extra but unfortunately im not familiar with the commands :(
directory:
movie.serie-apple
-- moviepart.r00
-- moviepart.r01
-- moviepart.r02
-- moviepart.r03
-- moviepart.r04
-- moviepart.rar

On the source panel im standing with the cursor on the directory "movie.serie-apple"
I push the menu bar button i put it on as usual, and create a directory with the same name on the opposite panel and entrr in it.
On the source panel also enter in the "movie.serie-apple" and searching for *.rar file and unpack it to the opposite panel's already entered directory.

I intentionally gave the name "movie.serie-apple" because with %O or %N gives truclated name "move" (i dont know why)
In the plugin extDir there is a "compatibility' switch, where this truncation solved.

Do you think is it solvable? or can someone make a plugin?
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Here's a PowerShell script for that.
Select an archive and start the script. It will create a new folder in the target panel with the same name as the archives parent folder.
It will then unpack the archive into that. After extraction it will open the folder in the target panel.

I'm using the console version of 7-Zip (7z.exe + 7z.dll) for extraction. Please adjust the path in the script.

Put the script on a button with:
Command:

Code: Select all

powershell.exe
Parameter:

Code: Select all

-NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\ThisScript.ps1' -dstPath '%T' -archive '%P%O.%E'}"
After testing you can set "Run minimized" and remove the "-NoExit"

Script:

Code: Select all

# TC Button Param:
# powershell.exe
# -NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\ThisScript.ps1' -dstPath '%T' -archive '%P%O.%E'}"

Param(
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$archive,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$dstPath
)

# Adjust the path to 7z.exe
$path7ZipExe = $env:COMMANDER_PATH + "\Tools\7-Zip\7z.exe"

# Check if started from TC
If((Test-Path -Path "env:COMMANDER_PATH") -eq $false)
{
    Write-Host "Please start from TC!"
    Exit
}

If ((Test-Path -Path $path7ZipExe) -eq $false)
{
    Write-Host "7-Zip.exe not found!`nCheck the script."
    Exit
}

$folderName   = Split-Path $archive -Parent | Split-Path -Leaf
$archiveDrive = Split-Path $archive -Qualifier

# Make sure we're not in the drive root
If ($folderName.ToLower().StartsWith($archiveDrive.ToLower()))
{
    Write-Host "In drive root! Exit"
    Exit
}

# Create target folder if it doesn't exist
If ((Test-Path -Path ($dstPath + $folderName)) -eq $false)
{
    New-Item -Path $dstPath -Name $folderName -Itemtype directory | Out-Null
}

# Unpack
$args7Zip = 'x ' + '-o"' + $dstPath + $folderName + '" "' + $archive + '"'
Start-Process -FilePath $path7ZipExe -ArgumentList $args7Zip -NoNewWindow -Wait

# Open new folder in TC target panel
$pathTCExe = $env:COMMANDER_EXE
$argsTC = '/O /S /R="' + $dstPath + $folderName + '"'
Start-Process -FilePath $pathTCExe -ArgumentList $argsTC -NoNewWindow
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Post by *gerappa »

Thank you for the help!

Your script is acting strange for me.
As you see in the attached picture the source is in d:\Torrent\ the cursor is on American.Idol-TVShow
The opposite panel is E:\1\

When i push the button, the script open a cmd window (pic2) and asking about overwrite (?)
If i select A, the unpack is fine. If i skip, the unpacked file size is 0 (pic3)
I think its just a switch in 7-zip.
The main problem is the directory creation. If you see the last picture, the directory is Torrent instead of American.Idol-TVShow
s18.postimg. org/jr9w27i3d/index.jpg
(sorry for spaceing but im not allowed to issue URLs)

You gave me a good hint about %P%O.%E so i started to explore with this setting the eXtended Make Directory plugin about Create directory on the opposite panel and ENTER it. This plugin is able to enter, but unable to handle names like xxx.yyy-zzz :(
I tried to look after for command for enter directory (like cd) but i couldnt use it.

What if we skip the unpack itself? Is it easier to solve?
Create directory on the opposite panel and enter it, meanwhile enter the source panel's directory (that's all)
i can manually select the rar and unpack...thats fine...

Thanks again for your help!
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

You have to select the .RAR file not the folder.

If you pass a folder to 7-Zip I guess it will try to extract all archives in it, including the split parts so it will ask if you want to overwrite.

The script without extraction:

Code: Select all

# TC Button Param:
# powershell.exe
# -NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\ThisScript.ps1' -srcPath '%P' -dstPath '%T'}"

Param(
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$srcPath,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$dstPath
)

# Check if started from TC
If((Test-Path -Path "env:COMMANDER_PATH") -eq $false)
{
    Write-Host "Please start from TC!"
    Exit
}

$folderName   = Split-Path $srcPath -Leaf
$srcDrive = Split-Path $srcPath -Qualifier

# Make sure we're not in the drive root
If ($folderName.ToLower().StartsWith($srcDrive.ToLower()))
{
    Write-Host "In drive root! Exit"
    Exit
}

# Create target folder if it doesn't exist
If ((Test-Path -Path ($dstPath + $folderName)) -eq $false)
{
    New-Item -Path $dstPath -Name $folderName -Itemtype directory | Out-Null
}

# Open new folder in TC target panel
$pathTCExe = $env:COMMANDER_EXE
$argsTC = '/O /S /R="' + $dstPath + $folderName + '"'
Start-Process -FilePath $pathTCExe -ArgumentList $argsTC -NoNewWindow
Button Parameter:

Code: Select all

-NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\ThisScript.ps1' -srcPath '%P' -dstPath '%T'}"
Start it from within the folder that contains the archive.

P.S. Please disguise your file names a little more ;)
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Post by *gerappa »

Ohhh,, YES!!!
Its working... my mistake was i selected the dir not the file :D
Thank you very much, you are fantastic!! :roll:
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Glad it works for you. I wrote the same functionality some time ago in AutoIt (for the exact same reason ;)) but since PowerShell is ubiquitous now, it was a good opportunity to convert it.
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Post by *gerappa »

LOL I use tcmd for years, and i just thought recent days about it. :D
well.... thanks again!
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Post by *gerappa »

Hello again
Still thank you for the script.
I tried to vary for WinRAR but something is not right, not doing the same as 7zip. What setting am i do wrong? (i just modified 7zip.exe to winrar.exe)
The main probleme is, its create the dir and everything, but the extracted file stays in the source directory not on opposite panel (for a moment its there but move it back)
Last edited by gerappa on 2016-04-10, 15:05 UTC, edited 2 times in total.
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Post by *gerappa »

the probleme somwhere is here with the unpack parameters only:
# Unpack
$args7Zip = 'x ' + '-o"' + $dstPath + $folderName + '" "' + $archive + '"'
Start-Process -FilePath $path7ZipExe -ArgumentList $args7Zip -NoNewWindow -Wait
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

WinRar uses slightly different parameters.

Try

Code: Select all

$args7Zip = 'x "' + $archive + '" "' + $dstPath + $folderName + '\"'
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Post by *gerappa »

Come ooooon..... it looks like there was no challenge for you at all.
Works like charm. I tried to replace to winrar couple of times during the year, but i was always failed. :roll:
Only one cosmetic thing, but its just for perfection:
When i push the button, a cmd window (powershell) pop-up before the winrar window, and stays 'till unpack finish. Is it can be disappear?
and THANK YOU THANK YOU THANK YOU :oops:
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Since it's not a command line application you can remove the "-Wait" from

Code: Select all

Start-Process -FilePath $path7ZipExe -ArgumentList $args7Zip -NoNewWindow -Wait
This will jump to the new directory immediately in TC.

If you use the command line "UnRar.exe" it would behave exactly like with 7z.exe
gerappa
Junior Member
Junior Member
Posts: 8
Joined: 2015-02-21, 11:54 UTC

Post by *gerappa »

It was worked!!!!
One more time again--- Thank you very much!
8) 8) 8)
Post Reply