Move zip to subdir, extract, delete

Discuss and share scripts and script files...
Post Reply
reebae
Posts: 17
Joined: 12 Aug 2020 13:57

Move zip to subdir, extract, delete

Post by reebae »

Hello,

I can't seem to complete this script. I have a zip file, I want it moved to a subdirectory of the same base name, then extract the zip "here", then delete the zip file. The first part of the script reads

Code: Select all

  $item = <get SelectedItemsNames>; 
  end (!$item), "No item selected!";
  $itemBase = gpc(gettoken($item, 1, <crlf>), "base");
  $newfolder = "<curpath>\$itemBase";
  moveto $newfolder, $item, , 2, 2;
  goto $newfolder;
  #280; // File | File Special | Extract Here
The deletion methods I've tried (indented properly in the file):

Code: Select all

#169;
delete 1, 1;
delete 1, 1, $newfolder;
$zipfile = "$newfolder/$newfolder.zip"; + goto that file then delete it
goto $newfolder; then delete it
Nothing negative happens, just the file is not deleted. I checked the Recycle Bin to be sure.

highend
Posts: 14578
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Move zip to subdir, extract, delete

Post by highend »

setting "BackgroundFileOps", 0;
As the first line

delete 1, 0, "<curpath>\$itemBase\$itemBase" . ".zip";
for the deletion...
One of my scripts helped you out? Please donate via Paypal

WirlyWirly
Posts: 274
Joined: 21 Oct 2020 23:33
Location: Win 10 @ 100% (3440x1440)

Re: Move zip to subdir, extract, delete

Post by WirlyWirly »

Just a heads up, the #280 command won't work if your archieve is password protected, at-least it doesn't for me with .7z files.

What I ended up doing is calling 7zG.exe to perform extractions, which will allow you to input a password if needed, supports a lot of archive formats, and even shows you a nice little progress bar if you use the right commands.

If you decide you'd like these features, here's the 7z commands I run that will do them. You can incorporate this into your script or use it as-is in a toolbar button, just point the script to where you keep 7zG.exe (download).

Code: Select all

Extract to "*\"|$selected_items = ''; foreach($file, "<selitems ::>", "::") { $selected_items = lax($selected_items -ai!"$file") }; run lax("$PORTABLEAPPS\7-ZipPortable\App\7-Zip64\7zG.exe" x -o".\*\" "-spe" "-an" $selected_items)|
Extract here|$selected_items = ''; foreach($file, "<selitems ::>", "::") { $selected_items = lax($selected_items -ai!"$file") }; run lax("$PORTABLEAPPS\7-ZipPortable\App\7-Zip64\7zG.exe" x -o".\" "-an" $selected_items)|

Since this command loops over the input files, you can extract any number of archives at once. The first option will extract into a folder of the same name and the second will extract into the current folder. I don't have it delete the archives, though I'm pretty sure 7z has a flag that you can add so that it will delete the archive upon successful extraction (just in case something goes wrong)...
Last edited by WirlyWirly on 28 Apr 2022 22:06, edited 2 times in total.

Norn
Posts: 483
Joined: 24 Oct 2021 16:10

Re: Move zip to subdir, extract, delete

Post by Norn »

Similar script without delete:
viewtopic.php?f=7&t=24424
Windows 11 24H2 @100% 2560x1440

reebae
Posts: 17
Joined: 12 Aug 2020 13:57

Re: Move zip to subdir, extract, delete

Post by reebae »

highend wrote: 28 Apr 2022 18:12 setting "BackgroundFileOps", 0;
As the first line

delete 1, 0, "<curpath>\$itemBase\$itemBase" . ".zip";
for the deletion...
Thank you for this. Changing "<curpath>\$itemBase" to "$newfolder" successfully deleted the zip file.
WirlyWirly wrote: 28 Apr 2022 18:25 Just a heads up, the #280 command won't work if your archieve is password protected, at-least it doesn't for me with .7z files.
I will come back to this and explore these and more 7-zip commands, as I really prefer to use 7-zip. Thank you.
Norn wrote: 28 Apr 2022 19:42
Similar script without delete:
viewtopic.php?f=7&t=24424
Thank you. It's a little beyond my KISS mantra, as I only need "unzip here" and "unzip to folder" to suit my needs.

WirlyWirly
Posts: 274
Joined: 21 Oct 2020 23:33
Location: Win 10 @ 100% (3440x1440)

Re: Move zip to subdir, extract, delete

Post by WirlyWirly »

reebae wrote: 29 Apr 2022 02:59 I will come back to this and explore these and more 7-zip commands, as I really prefer to use 7-zip. Thank you.
If that's the case then you might be interested in this command too, it's the one I use to create archives from selected items. It will open the selected files in 7z's "Add to Archive" window, which lets you set passwords, parts, etc.

All 3 of these commands give you the same functionality and feedback interfaces that you would get from the right-click menu after installing 7z. I just replicated the behavior into XY in a way that would be portable.

Code: Select all

Add to archive...|$selected_items = ''; foreach($file, "<selitems ::>", "::") { $selected_items = lax($selected_items -i!"$file") }; run lax("$PORTABLEAPPS\7-ZipPortable\App\7-Zip64\7zG.exe" a $selected_items -ad -saa -- "<curitempath>\<curbase>")|
I'll probably take these commands and package a nice little toolbar button, I'm sure there's at-least a few people that would like to have the right-click options of 7z as portable.

Post Reply