When autocreateDirectory is true, and the top level directory did not exist, the mkdirs failed because the adapter tried to create a directory name with a zero length string. This caused an 'String index out of range: 0' exception in SFTP. Stop iteration when 'pathSegment' is zero length.