Page 1 of 1
Move zip to subdir, extract, delete
Posted: 28 Apr 2022 17:51
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.
Re: Move zip to subdir, extract, delete
Posted: 28 Apr 2022 18:12
by highend
setting "BackgroundFileOps", 0;
As the first line
delete 1, 0, "<curpath>\$itemBase\$itemBase" . ".zip";
for the deletion...
Re: Move zip to subdir, extract, delete
Posted: 28 Apr 2022 18:25
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)...
Re: Move zip to subdir, extract, delete
Posted: 28 Apr 2022 19:42
by Norn
Similar script without delete:
viewtopic.php?f=7&t=24424
Re: Move zip to subdir, extract, delete
Posted: 29 Apr 2022 02:59
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.
Thank you. It's a little beyond my KISS mantra, as I only need "unzip here" and "unzip to folder" to suit my needs.
Re: Move zip to subdir, extract, delete
Posted: 29 Apr 2022 05:10
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.