Improve the logic for testing whether one directory is the prefix of another