Page 1 of 1
Catalog item to create zip from selected files
Posted: 25 Nov 2019 15:59
by nsyrax
Is there an easy way to create a catalog item to create a zip file by dragging files onto it? Ideally, it would prompt for a file name, but if I could set one by default, that would be fine as well.
Re: Catalog item to create zip from selected files
Posted: 25 Nov 2019 16:21
by highend
Sure, script it. get("drop") contains the items that are dragged over
an entry in the catalog.
Re: Catalog item to create zip from selected files
Posted: 25 Nov 2019 16:48
by nsyrax
Please excuse my n00bness, but not exactly sure how to set this up. Any additional info would be VERY welcomed!
[UPDATE] I found your post with the script below
Code: Select all
$zip = "<path to 7-zip>\7zG.exe";
$sel = quote(get("SelectedItemsPathNames", '" "'));
$cnt = get("CountSelected");
if ($cnt > 1) { $zipName = "<curpath>\" . trim(gpc(<curpath>, "base"), ":", "R") . ".7z"; }
elseif ($cnt == 1) { $zipName = gpc(<curitem>, "base") . ".7z"; }
else { status "No item(s) selected, aborted!", "8B4513", "stop"; end true; }
run """$zip"" a ""$zipName"" -ad $sel", , 0, 1;
and it seems to work, but is there a way to do it without any dialog?
Re: Catalog item to create zip from selected files
Posted: 25 Nov 2019 17:35
by highend
What dialog? 7z's? There is zip_add(). And that script doesn't work by
dragging but by selected items (if this makes a difference...)
Re: Catalog item to create zip from selected files
Posted: 25 Nov 2019 17:43
by nsyrax
My mistake. Disregard the 7zip script.
Re: Catalog item to create zip from selected files
Posted: 25 Nov 2019 19:59
by nsyrax
Back to the original ask, I added the get("drop") script, but it doesn't seem to actually do anything.
Re: Catalog item to create zip from selected files
Posted: 25 Nov 2019 23:22
by highend
Code: Select all
$items = <get drop |>;
$name = input("Enter .zip file name", ".zip will be added automatically!", gpc(gettoken($items, 1, "|"), "base"));
if (substr($name, -4) UnLikeI ".zip") { $name .= ".zip"; }
zip_add("<curpath>\$name", $items);
Re: Catalog item to create zip from selected files
Posted: 26 Nov 2019 13:46
by nsyrax
Perfect! Many thanks!