Check if the URL is a directory before attempting to scan it

I got alot of scandir errors on files. So I changed the code a little to check if it's a directory before attempting to scan it.