Im fairly new to bash but I wanted to know about an idea I had to stream my file process these days. I modify .html, and .xml files and usually will take the files right click, create .zip, add files, rename, and cut the zip out of the folder and paste into another folder. I KNOW bash should be able to do this but Im still fairly new into HOW and WHAT is going on.
From reading around and searching here I get this idea:
#!/bin/bash
##Location of files
DIR="/mnt/windows/files"
##Location of files being zipped
PROCESS="/mnt/windows/running"
##completed zipped files
ZIPPED="mnt/windows/zipped"
##original location of files
ORIG="mnt/windows/originals"
cd "$DIR"
## Move files locally
cp -v $DIR/* $PROCESS
mv -v $DIR/* $ORIG
## check directory being process
cd $PROCESS
for folder in $(ls "$PROCESS"); do
echo
echo ===========================
echo
zip -x $PROCESS/$folder
mv -v $PROCESS/$folder
done
You can just zip the files and then remove them if the zip process was sucessful, Check out the following example:
#!/bin/bash
# Location of files to zip
DIR="/mnt/windows/files"
# Location where to create zip files
ZIPPED="/mnt/windows/zipped"
# Zip files
zip $ZIPPED/zipfile $DIR/*
# Remove files zipped
if [ $? -eq 0 ]; then
rm $DIR/*
else
echo "**Error occurred during zip..."
fi
I found this last night when I was doing a search. Now the issue is the zip file creates the folder structure with the zip which is not what I need. Meaning: Folder>Folder>Folder>contents because the bash script calls the directory
# Zip files
zip -j $ZIPPED/zipfile $DIR/*
-j Store just the name of a saved file (junk the path), and do not
store directory names. By default, zip will store the full path
(relative to the current path).