Properly detect directories (v2)

Fixes #366, obsoletes #371. Filesystem information used in addition to trailing slash via @arty-name 

I've also added tests to check against.