Created
February 24, 2012 03:12
-
-
Save xurizaemon/1896970 to your computer and use it in GitHub Desktop.
Restoring files which were bulk copied from a complex folder hierarchy to a flat structure in My Pictures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# where the files went missing from | |
LIBRARY1="/Volumes/Image_Library/Clients" | |
LIBRARY2='/Volumes/Image_Library/CLIENTNAME' | |
# where the files ended up | |
RECOVERED="/Volumes/My Pictures" | |
# files to output reports to | |
REPORT_MISSING=report-missing.txt | |
REPORT_FOUND=report-found.txt | |
# blow away the old reports | |
for ii in $REPORT_MISSING $REPORT_FOUND ; do | |
if [ -e $ii ] ; then | |
rm $ii | |
fi | |
done | |
# iterate through libraries | |
for LIBRARY in $LIBRARY1 $LIBRARY2 ; do | |
# find all dot-underscore files | |
find "$LIBRARY" -name '._*' | while read DOTFILE ; do | |
# extrapolate the proper path + filename | |
REALFILE=$( echo $DOTFILE | sed -e 's#\._##g' ) | |
# and just the filename | |
FILENAME=$( basename "$REALFILE" ) | |
# if the proper doesn't exist | |
if ! [ -e "$REALFILE" ] ; then | |
# don't bother with this file, there are billions | |
if [ "$FILENAME" != ".DS_Store" ] ; then | |
# if there is a copy in the $RECOVERED dir | |
if [ -e "$RECOVERED/$FILENAME" ] ; then | |
# copy it back to the desired location | |
cp -av "$RECOVERED/$FILENAME" "$REALFILE" >> $REPORT_FOUND 2>&1 | |
else | |
echo "Can't find $RECOVERED/$FILENAME" >> $REPORT_MISSING | |
fi | |
fi | |
fi | |
done | |
done | |
# tell us how it worked out | |
if [ -e $REPORT_MISSING ] ; then | |
echo "Unable to find the following files" | |
cat $REPORT_MISSING | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment