Added checking for the end marker while scanning a directory