Check variable type before using readdir to avoid surprises and fix #4667 #4658 and #4613
fix unknown var in if clause
one check is enough
Merge pull request #4701 from owncloud/fix_4667

Always check variable type before using readdir to avoid surprises, fixes #4667 #4658 and #4613