If a teamproject is possible, i could offer the part where files get extracted (zip) without need to decompress to temp folder.-KodeZwerg
A temporary folder created in the destination folder is the easiest method:
1. Extract contents to new temporary folder using 7-Zip command, (or library routines)
2. Get contents of temporary folder
3. Determine types of contents, (don't even need to do that, just count the number of items)
4. Contents:
- If a single file/folder move it to the parent folder and delete the temporary folder
- If multiple files/folders rename temporary folder to archive name sans extension
5. Go make a cup of coffee
Pretty easy in Powershell but not really any provision for a hotkey so simpler in AHK, AutoIT, or some other language.
Proof of concept (no error checking at all):
<#
Uses 7Zip4Powershell module: https://www.powershellgallery.com/packages/7Zip4Powershell/1.9.0
.\ExArc.ps1 <archive> <destination>
<archive> = full path to archive with quotes if necessary
<destination> = destination path with no trailing \
#>
Param (
[string]$archive,
[string]$dest
)
$tempdest = $dest + '\temp7zip'
Expand-7Zip -ArchiveFileName $archive -TargetPath $tempdest
$items = Get-ChildItem -Path $tempdest
switch ($items.Count) {
1 {
Move-Item $items[0].FullName $dest
Remove-Item $tempdest -Recurse -Force
}
0 {
Write-Host "Ain't nuffin' there!"
}
default {
Rename-Item $tempdest ($dest + '\' + ([io.path]::GetFileNameWithoutExtension($archive)))
}
}
BTW, referring to the OP I'm assuming
TC = Total Commander which is what he wants it to work with, correct?
Maybe Total Commander has a Powershell interface, (see
here)?
So, in theory, TC can set a hotkey that passes the selected objects, (archives), to a Powershell script that does the above for each file.
DISCLAIMER: I don't use Total Commander.
Using the info at that link apparently %L is a temp text file containing a list of selected files. This will probably need tweaking, (not to mention checking for existing files/folders), to stop/redirect output, etc but it should be a start:
Command: PowerShell -NoProfile -NoExit -ExecutionPolicy Bypass -File "%COMMANDER_PATH%\TOOLs\CMDs\ExArc-TC.ps1"
Parameters: '% L'
Start Path:
Icon File: Powershell
Tooltip: Extract each archive
<#
*** REQUIRES ***
7Zip4Powershell module: https://www.powershellgallery.com/packages/7Zip4Powershell/1.9.0
.\ExArc-TC.ps1 <textfile>
<textfile> = list of archives: full path, one per line
#>
Param (
[string]$selFiles
)
$files = Get-Content $selFiles
ForEach ($file in $files) {
$dest = [io.path]::GetDirectoryName($file)
$tempdest = $dest + '\temp7zip'
Expand-7Zip -ArchiveFileName $file -TargetPath $tempdest
$items = Get-ChildItem -Path $tempdest
switch ($items.Count) {
1 {
Move-Item $items[0].FullName $dest
Remove-Item $tempdest -Recurse -Force
}
0 {
Write-Host "Ain't nuffin' there!"
}
default {
Rename-Item $tempdest ($dest + '\' + ([io.path]::GetFileNameWithoutExtension($file)))
}
}
}