0

I want to create a batch/shell script for windows and mac that will take few different files with different types and will compress it to a .zip file.

I already saw a few questions and answers about it, but all of them either compress all the files in the folder or compress them individually.

Example (look at attached image): I have a folder that contains 1.txt, 2.xml, a sub directory. And I want to turn all of them into a .zip file.

If possible to get a solution both for windows and Mac.

example

Dgot
  • 119
  • 3
  • 14
  • check [this](http://stackoverflow.com/questions/28043589/how-can-i-compress-zip-and-uncompress-unzip-files-and-folders-with-bat) and [this](https://coolestguidesontheplanet.com/how-to-compress-and-uncompress-files-and-folders-in-os-x-lion-10-7-using-terminal/) – npocmaka Apr 23 '17 at 10:21
  • I'm currently using the following command: for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\" The problem is that it's making each file / directory into an individual zip file. any suggestions to edit it? – Dgot Apr 24 '17 at 06:56

1 Answers1

0

On Windows there is the file 7zip.chm in directory %ProgramFiles%\7-Zip which is the help file of 7-Zip. Double click on this file to open the help.

On Contents tab there is the list item Command Line Version with the help pages:

  • Syntax ... Command Line Syntax
  • Commands ... Command Line Commands
  • Switches ... Command Line Switches

The target is to compress everything in folder test into a ZIP file with name of the folder as file name.

This could be done for example with the command line:

"%ProgramFiles%\7-Zip\7z.exe" a -bd -mx=9 -r -y -- test.zip "C:\Path to Directory\test\*"

This command line adds (a) everything in directory C:\Path to Directory\test recursive (-r) to a ZIP file with name test.zip in current working directory without progress indicator (-bd) using best ZIP compression (-mx=9) with assuming Yes on all queries (-y).

In other words the file test.zip in current directory contains after execution the subdirectory main with everything inside and the files 1.txt and 2.xml.

Mofi
  • 46,139
  • 17
  • 80
  • 143