Detect directories correctly