Added check for the path being a directory