How to create a zip file by a key press?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
srikat
Posts: 11
Joined: 15 Apr 2007 05:30
Contact:

How to create a zip file by a key press?

Post 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.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

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

Post 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");
Last edited by TheQwerty on 02 Jun 2009 21:28, edited 1 time in total.

srikat
Posts: 11
Joined: 15 Apr 2007 05:30
Contact:

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

Post 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?

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

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

Post by TheQwerty »

Small typo.. should be just "a" not "-a".
I've corrected it above.

Post Reply