Divide 7zip into multiple zips based on names of content files

66 Views Asked by At

I have a bunch of very large 7zip files (up to 40 GB). Each of them contains thousands of individual files. What I need to do is split them out based on the names of the content files.

For example, what I have is one zip per year with some files matching file_a_....txt pattern in the file names and then a whole lot of other files with all different names.

What I currently have (1 7z per year)

examplezip_2010.7z
├── file_a_1.txt
├── file_a_2.txt
├── file_a_3.txt
├── file_a_....txt
├── otherfile.txt
├── randomfile.txt
└── ....txt

What I want is 1 zip (7z/zip I don't care) with all my file_a_....txt and another with all the other files. Ie:

A_file_zip_2010.7z
├── file_a_1.txt
├── file_a_2.txt
├── file_a_3.txt
└── file_a_....txt

And

Other_files_zip_2010.7z
├── otherfile.txt
├── randomfile.txt
└── ....txt

I would like to do this from the command line/bat file or similar as I need to do it for a whole lot of 7zip files. I have tried using the following bat, it does work, but the last script is (I believe) effectively making 2 individual 7zips and then deleting the original so it is very slow as it is re copying all of the files. The file_a_... files I want to separate out are typically only about 2% of the total 7z so if I can avoid moving/changing things with the other 98% should hopefully speed things up tremendously.

I'm not wedded to 7zip, but received the files as 7z so need any option to work with that. All running on windows computer.

Batch attempt:

set filepref=file_a_
set yr=2012

REM extract files matching regex to folder
7z.exe e "examplezip_%yr%.7z" -r -o".\%filepref%_%yr%" -i!%filepref%*

REM zip new folder
7z.exe" a -t7z "%filepref%_%yr%.7z" ".\%filepref%_%yr%\*.*"

REM delete files matching regex to folder
REM this is the step which seems to recopy everything
7z.exe d "examplezip_%yr%.7z" %filepref%* -r
0

There are 0 best solutions below