Page 1 of 1

How to create a zip file by a key press?

Posted: 02 Jun 2009 14:29
by srikat
I want to press press Alt+F5 to compress selection to a zip file.

Case 1

If the selected item is a single folder or file, then the zip file should get the same name as the folder or file.

I am trying the following:

Code: Select all

"WinRAR" a "<curbase>" <items>
With the above, when I press Alt+F5 with a folder named 'test' selected (whose path is 'C:\sridhar\websites\test'), XYP is generating the 'test.zip' file. But when this zip file is opened, it contains a folder named 'sridhar' and inside that another folder named 'websites' and inside that finally the desired one 'test'.

What is the correct script to stop the zip file from being created with the folder structure?

Case 2

If multiple items are selected (i.e., multiple folders or multiple files or files+folders) the resulting zip file should get the name of the parent folder.

Can anyone give me the script for this?

Thanks in advance.

Re: How to create a zip file by a key press?

Posted: 02 Jun 2009 15:23
by TheQwerty
Case 1 is a problem with the arguments you're giving WinRAR, you need to include -ep1 to not store the base path.
Case 2 is solved by using GetInfo("CountSelected");

This should probably work for both cases:

Code: Select all

"Archive"
  $name = (GetInfo("CountSelected") == 1) ? "<curbase>" : "<curfolder>";
  //Args:
  //-a = Archive
  //-afzip = Create a ZIP archive.
  //-ep1 = Do not store base path.
  //-m5 = Maximum compression.
  OpenWith("""WinRAR"" a -afzip -ep1 -m5 -- $name <items>", "s");

Re: How to create a zip file by a key press?

Posted: 02 Jun 2009 21:24
by srikat
I have saved this code as script.xys

User -> Load script file -> Zip Unzip (the caption I gave to the UDC)

with a file selected shows a Error dialog with the message

Code: Select all

Unknown option "a"
. Upon pressing OK, a warning dialog says

Code: Select all

No archives found
.

How do I use your code?

Re: How to create a zip file by a key press?

Posted: 02 Jun 2009 21:29
by TheQwerty
Small typo.. should be just "a" not "-a".
I've corrected it above.