Checks if last directory exists before using it