Check dir cache after SubstitutePath.
Make sure dir ends with slash when check cache.
Merge pull request #2608 from ulion/check_dir_exists_use_dircache_fix

Fix problems introduced by PR2496 (check dir exists use dircache)