Skip to content

Instantly share code, notes, and snippets.

@JavierAroche
Last active May 8, 2018 10:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JavierAroche/cf6fc557f0be697a1f3238abaa88b2e4 to your computer and use it in GitHub Desktop.
Save JavierAroche/cf6fc557f0be697a1f3238abaa88b2e4 to your computer and use it in GitHub Desktop.
Find corrupted files using GM identify
folderToCheck='/Volumes/16TB/whatever/path'
outputFile=~/Desktop/files.txt
counter=1
Red="\033[0;31m" # Red
Green="\033[0;32m" # Green
Color_Off="\033[0m" # Text Reset
cd ${folderToCheck}
# Find all files and get count
count=$(find "$(pwd)" -type f -iname *.psd -o -iname *.psb | wc -l | xargs) # Optional count
# Find all files and iterate through all
find "$(pwd)" -type f -iname *.psd -o -iname *.psb | while read -r line ; do
result=$(identify "${line}")
if [ "$result" ] ; then
echo "OK $line" >> $outputFile
status=${Green}
else
echo "ERROR $line" >> $outputFile
status=${Red}
fi
echo "${status}File ${counter} of ${count}${Color_Off} → ${line##*/}"
counter=$(( $counter + 1 ))
done
echo "Wrote file ${outputFile}"
echo "-------------- DONE --------------"
@undavide
Copy link

undavide commented May 8, 2018

Hi Javier!
I had to wrap in quotes the ${folderToCheck) in line 9 (i.e. cd "${folderToCheck}"), because otherwise a path with white spaces would break the cd command. The file extensions, too, must be wrapped in quotes ("*.psd"). I also had to add -e flag to echo, see my updated gist here – I don't know if I can issue a pull request for gists :-) Thanks again!!

@undavide
Copy link

undavide commented May 8, 2018

Uhmm... actually it passes a psb file that is corrupted... I will investigate and report back!

UPDATE
It turns out that a PSB which has corrupted layers, but an OK composite image will pass the identify test without the -verbose flag (that's the reason why your original code was ultra-fast compared to mine). I've added -verbose, and apparently it works, even if I don't know enough shell scripting to understand why it is able to discern whether "$result" is an OK message or an Error :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment