ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Post New Requests Here

Request: Ahk script to extract archive to subfolder of current directory

<< < (2/3) > >>

If a teamproject is possible, i could offer the part where files get extracted (zip) without need to decompress to temp folder.
I could integrate full zip function inside own app, so checking if there is a file in root of archive aint a pain to me.
I could do a CLI, like first parameter is zip filename and second root of destination folder.
The hotkey part, how to get archive filename, how decide destination name, there i am clueless.
Okay, as destination root i could easy extract archives path, but still no idea how to get a archive filename just by pressing some keys.

If such is helpful, let me know.

If a teamproject is possible, i could offer the part where files get extracted (zip) without need to decompress to temp folder.-KodeZwerg (November 12, 2018, 03:29 PM)
--- End quote ---

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):

--- Code: PowerShell ---<#  Uses 7Zip4Powershell module: .\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

--- Code: PowerShell ---<#  *** REQUIRES ***    7Zip4Powershell module: .\ExArc-TC.ps1 <textfile> <textfile> = list of archives: full path, one per line#>  Param (  [string]$selFiles) $files = Get-Content $selFilesForEach ($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)))      }  }}

thx for your help!!! :Thmbsup: :Thmbsup:
after reading your comments. now let me make my request clear:  use hotkey+click to wisely extract a small size archive file.

@curt may concern it take much more time if  Extract the archive to a temporary folder. extraxt+move file mean double time. So i revise my request: I only use this way when i want to extract a small size file. As to extract a large size archive, i do it in the normal way(check the files manually then choose the right content menu to extract it).  In briefly, we focus on small size file. so @4wd s idea is OK for me.
 @KodeZwerg  ALT+Win+leftclick, i don't know whether ahk can get the files name when i click it, the point is how to know whether there is multi files in a archive. it seems you know how to do it.
@4wd thx for your hard work. but i don't know how to use it. i will google the powershell usage
sorry for my English

I find a way to solve my problem
1. extract the file in a subfolder(its name based on the archive files name of course). (no matter there is multi files in it or not)
2. check files number in it(one or multi)
3. if multi       then nothing need to do
    if one         then use this AHK script rescue orphans  which can make a file/folder move to their parent dir.

i hope it can help you guys.

@Scripters, why dont use List command to get archive content to compare? Just my Idea to Script stuff where i aint have any idea at all :-]
At least that way i would go if i write a batch file.

@chashnniel For Zip fileformat that is easy action to get content. But as said, i have no idea on how to get Archive filename.

There exists some multipurpose CLI dearchivers that can list content, as more archive formats needed as more my first of all zip only variant would fail :-)


[0] Message Index

[#] Next page

[*] Previous page

Go to full version