write *.7z for each File

Nov 16, 2012 at 3:43 PM
Edited Nov 16, 2012 at 3:46 PM


greets out of Germany and sorry if my english isnt so nice ;-)

@first: this script seems to be a really good job. I'll test it little bit and for the things i need it is nearly perfect.

For me as PS newby it is hard to understand the script and i' dont know if there is a way in the script self.

SOme Background information: I want to 7zip one folder, where my Backup tool depositing his backup files. These files aren't very compressed an 7zip give me nearly 60% compression-ratio.@ the moment, i do this with a cmd script and a loop, which goes about all files. And per file there is one 7z. there are about 20 to 150 files which has a Session-ID. Next files name is + 1

So, i think u knew my question already, is there a possibility to create one 7z per file., with the 7zbackup Powershell script?

I thought that it could be possible by generating the selection.txt per file and then start it with the 7zbackup script with the generated selection.txt, but this seems to be so artless. And theres so much logic in the script, perhaps it is possible with a small adaption or it is in it.

Thanks for any help and any answer

greets out of germany


Nov 16, 2012 at 6:00 PM

Hi Jimanju,

welcome and thanks for the compliments.

To answer your question directly ... no, this script has been designed to create a single archive to contain multiple files from multiple directories.

However there might be a solution to accomplish your task using the flexible directive system which is implemented by the script. If I understand the behave of your environment we are in this scenario:

  • You have a backup container directory. Let's assume it's named "X:\Backups" (it's only a convention, it might be whatever)
  • You have a backup tool which creates it's own archives named with a specific session-id as suffix (or prefix).
  • There might be multiple files for session and in this case each subsequent file is named with a +1 increment number

If this is the case I have to assume that each session-id corresponds to a different cycle of the scheduled backup (do you run nightly backups ?). In this scenario, if I understand well, you want to compress all newly generated files into compressed ones. So in other words, all the files in the backup directory generated from the previous backup cycle. To accomplish this you might create a selection (let's call it selection.txt) file with this directives


and run the PS script like this

.\7zBackup.ps1 --type MOVE --selection selection.txt

this will move into a single archive all backup files generated yesterday.

Nov 16, 2012 at 9:31 PM


thanks for the fast answer.

To the behavior of my enironment, yes i think u understand it right, here it is in a little bit more detail

  • Yes, I have a Backup Container, like that
  • Its a Daily DIFF Backup, which saves much of Data every Night.
    • The Backup Tool saves this in Containers which named like "B000456.backup"
    • There are about 20 to 150 files each night (Backup tool, divide the whole backed up Data in Container by the Source
      • for example: B000456.backup --> contains all of Source A
      • B000457.backup --> contains all of Source B


So if you probably could understand the Backup goes to an extra OFFSITE after a couple of days, and they have to use as less as possible space. In case i have to restore some data from the OFFSITE, which is zipped, it would take much more time to unzip and copy the file from the source i need. Conclusion, a single file isnt a choice. Futhermore, i think there are more reasons to get one file in one zip.

So perhaps something like that would be added in the next versions.

I think about a parameter in selection.txt which says that all files of this source getting a own zip. Or that the alias get a own zip...

Something like that.

Until then I try to catch the whole script and perhaps (in time, i cant define) i add som logic to the script, to use the feature i described.

however it stays very nice script. :-)

grtx outta Germany


Nov 23, 2012 at 6:16 PM

Hi Jimanju,

I well understand now your needs but, at present, this is not what my script was meant for. The whole thing is wrapped around the scope to create a single archive from multiple different sources while you're trying to achieve exactly the opposite : have multiple files to be compressed one-by-one in their own archive.

Nevertheless I hope my script gives you some clue to implement a for-each file loop in your directory to invoke 7zip properly and have your backups compressed properly.

All the best.