Fix test_directory_map

See #2475 and point 2 of #2334
Fix directory_map() for unit testing on Windows

opendir() was failing on VFS because of trailing backslash

See point 1 of #2334
Another directory_map() unit testing fix

is_dir() was failing on VFS too. I had to refactor a little bit, but it works exactly the same.