All pastes #3792624 Raw Edit

Libre Unzip

public unlisted text v1 · immutable
#3792624 ·published 2017-04-07 22:02 UTC
rendered paste body
#!/bin/bash
#    A script for extracting Microsoft Word Documents from zips in a directory.

#    Copyright (C) 2017, Trisquel Fora user Soon.to.be.Free
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    If you are using GNU/Linux, you should have received a copy of the GNU General Public License
#    along with your operating system.  If not, or if you are using a different operating system,
#    see <http://www.gnu.org/licenses/>.

WS_EXTRE="\.doc$|\.docx$"
WS_DIREXT=""

if [ -d "$HOME"/Downloads/DocsFound ]; then
	echo "Error: Directory ~/Downloads/DocsFound already exists. Exiting."
	exit 5
fi
mkdir "$HOME"/Downloads/DocsFound

find . -name "*.zip" -type f -print | while read WS_FILE;
do
	echo "Handling Archive ${WS_FILE}..."
	echo
	echo
	echo
	unzip -Z1 "$WS_FILE" | egrep "$WS_EXTRE" | while read WS_EXTFILE;
	do
		if [ "x$1" == "x-l" ]; then
			WS_DIREXT=`basename "$WS_FILE"`
			mkdir "$HOME"/Downloads/DocsFound/"$WS_DIREXT"
		fi
		
		echo "Extracting ${WS_EXTFILE}..."
		unzip -q "${WS_FILE}" "${WS_EXTFILE}" -d "$HOME"/Downloads/DocsFound/"$WS_DIREXT"
	done
done