checkPath function