24

I have one folder which will contain below mentioned files:

destiny.txt
destiny1.txt
destiny2.txt
destiny3.txt
destiny4.txt
destiny5.txt
destiny6.txt
destiny7.txt

Out of which destiny1.txt, destiny4.txt, destiny6.txt are from batch1.

I am using 7zip to zip the files.

Can I pass these 3 files in a single step to create DestinyTest.zip?

Is it possible?

1

3 Answers 3

29

Can I pass these 3 files in a single step to create DestinyTest.zip?

You can use the command line version of 7zip which is 7z.

From a command line:

7z a -tzip DestinyTest.zip destiny1.txt destiny4.txt destiny6.txt
  • a - Adds files to archive.
  • -tzip - Specifies the type of archive (we are creating a zip archive).

Further reading

0
8

If you have a file listing the files to make the zip, eg

create a list of files to archive, one on each line. This is an @-list, from DOS days, a number of proggies will do this for each line.

You can create such a file with dir /b destin*.* > zipme.lst, and then remove lines in a ascii editor (notepad or edit).

type zipme.lst destiny1.txt destiny4.txt destiny6.txt 7za a -tzip DestinyTest.zip @zipme.lst

This will find zipme.lst, and add all the files listed in it. It can be longer than the command-line, and you have some control over it.

0

I had a similar problem and wanted to do it with a batch script. Here is how:

In the example below, the script looks for all .csv files starting with "cell_cfg" and "slave_cfg", collects them, and zips them in one file called 'cfg.7z' stored in a subdirectory called 'zip':

@ECHO OFF
setlocal enableDelayedExpansion
mkdir zip
ECHO collecting filenames...
set filenames="C:\Program Files\7-Zip\7z.exe" a -t7z "zip/cfg.7z
FOR %%i IN (cell_cfg*.csv) DO (
    ECHO "%%i" | FIND /I "zip_cfg.bat" 1>NUL) || (
        SET filenames=!filenames!" "%%i
    )
)
FOR %%i IN (slave_cfg*.csv) DO (
    ECHO "%%i" | FIND /I "zip_cfg.bat" 1>NUL) || (
        SET filenames=!filenames!" "%%i
    )
)
set filenames=%filenames%"
%filenames%

(Adjust the path of your 7z.exe and files/folder names. If you want .zip instead of .7z, rename the lines:

set filenames="C:\Program Files\7-Zip\7z.exe" a -t7z "zip/cfg.7z

into

set filenames="C:\Program Files\7-Zip\7z.exe" a -tzip "zip/cfg.zip

)

I saved it as 'zip_cfg.bat' and place it in the folder with the files I want to zip. Then I can call it in the command line: first, navigate to the folder with the files, then just call:

zip_cfg.bat

In case you want to zip all files in the folder ("*"), the 'FIND /I "zip_cfg.bat" 1>NUL' part stops the script from zipping the batch file itself.

Hope this helps someone... :)

You must log in to answer this question.

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