Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 100 files that look like this:

001.txt
002.txt
003.txt
004.txt
.....
100.txt

I want to compress them like this:

001.txt
002.txt ----> archive01.7z
003.txt
---------
004.txt
005.txt ----> archive02.7z
006.txt

How can I achieve this using 7-Zip?

share|improve this question
    
If you have 100 files and each 7zip file contain 3 files, then the last 7zip file will only contain 1 file. -> Is this part of the requirement too? – Larry Morries Sep 27 '11 at 8:24
up vote 2 down vote accepted

Well, that depends .... If you're running Linux or a Linux-like shell (e.g. cygwin) in Windows, it's a simple program to write in bash or your favorite language like python or perl.

Here's some (untested ;) ) pseudo code (somewhat close to bash, but without a whole lot of extra needed syntax).

I=0  ##File counter
J=1  ##Archive counter
## the following while strategy will work in most languages as long as you don't 
## have thousands of files - if you do, read them in 1 at a time in the loop

while FILE in <list-of-files-to zip>  ## Loop across all files like *.txt
do
  if I mod 3 == 0  ## If we're at the start of a new archive
  then
    COMMAND="7z -a archive"J".7z " FILE " "  ##Start a new command line for archive "J"
    J++
  else
    COMMAND=COMMAND FILE   ##append the next file name to the command string
    if I mod 3 == 2        ## if the desired number of files are appended 
    then
      append COMMAND string to a script file to run later
      or run it directly right here
      COMMAND=""            ## clear the COMMAND string
    fi
  fi
  I++
done

## Handle left over files
I--   ## Loop increments I after last file
if I mod 3 != 2
then
  append COMMAND string to a script file to run later
  or run it directly right here
fi

You can change the "3" to a variable (SIZE) to build archives with a different number of files. If you do do, then the "2" becomes SIZE-1.

HTH

share|improve this answer
    
Thank you for your efforts and sorry for not pointing out I use Windows 7. I have got a perfect solution from stackflow but I'm sure your script will be helpful if I start to use cygwin someday:D – WTFIsGoingOn Oct 8 '11 at 6:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .