Gah, I had fixed the endif to fi while I was testing it and writing the post, but forgot to actually make the change in my post before submitting. xD

The ls -p was there because at first I wanted to test if a element in $file was a dir by checking if it ended with a "\", but the -d test made that useless, and I forgot to remove the p switch.