7zip Extract Encrypted files

From Michael's Information Zone
Jump to navigation Jump to search

I had a very large number of encrypted zip files created using 7zip. These needed to be decrypted so I wrote out the following script to run while I did more important things.
The key is that you know the file structure inside your archives. For me this was

  1. Directory holding the zipped files
  2. The encrypted zipped files
  3. Sub directory inside encrypted zipped files
  4. The files

I needed to recreate this structure in an un-encrypted form so this would be a nested looping script. The only "issue" is that the script outputs the directories with the .zip extension. I was just too lazy to remove it from the directory name but would be an easy addition to the script.

#!/bin/bash
ls -1 /source/directory > /tmp/filelist1
while read line
do
  	ls -1 /source/directory/$line > /tmp/foundzip
        while read line2
        do
          	mkdir -p /destination/directory/$line/$line2
                7za x -ppassword /source/directory/$line/$line2 -o/destination/directory/$line/$line2
        done < /tmp/foundzip
done < /tmp/filelist1
rm -f /tmp/foundzip
rm -f /tmp/filelist1