private void makeDirectories ( String dirPath , String permissions ) throws IOException { if ( ! dirPath . contains ( "/" ) ) return ; String [ ] pathElements = dirPath . split ( "/" ) ; if ( pathElements . length == 1 ) return ; // if the string ends with / it means that the dir path contains only directories, // otherwise if it does not contain /, the last element of the path is the file name, // so it must be ignored when creating the directory structure int lastElement = dirPath . endsWith ( "/" ) ? pathElements . length : pathElements . length - 1 ; for ( int i = 0 ; i < lastElement ; i ++ ) { String singleDir = pathElements [ i ] ; if ( singleDir . isEmpty ( ) ) continue ; if ( ! ftpClient . changeWorkingDirectory ( singleDir ) ) { if ( ftpClient . makeDirectory ( singleDir ) ) { Logger . debug ( LOG_TAG , "Created remote directory: " + singleDir ) ; if ( permissions != null ) { setPermission ( singleDir , permissions ) ; } ftpClient . changeWorkingDirectory ( singleDir ) ; } else { throw new IOException ( "Unable to create remote directory: " + singleDir ) ; } } } }
Creates a nested directory structure on a FTP server and enters into it .