Properly detect directories

Fixes #366, obsoletes  #371. Filesystem information used in addition to trailing slash.