protected void performDirectoryExport(GridFileType directory, File targetDirectory, StorageClient sms)throws Exception{
if(!targetDirectory.exists()|| !targetDirectory.canWrite()){
throw new IOException("Target directory <"+to+"> does not exist or is not writable!");
}
if(!targetDirectory.isDirectory()){
throw new IOException("Target <"+to+"> is not a directory!");
}
GridFileType[]gridFiles=sms.listDirectory(directory.getPath());
for(GridFileType file: gridFiles){
if(file.getIsDirectory()){
if(!recurse) {
System.out.println("Skipping directory "+file.getPath());
continue;
}
else{
File newTargetDirectory=new File(targetDirectory,getName(file.getPath()));
boolean success=newTargetDirectory.mkdirs();
if(!success)throw new IOException("Can create directory: "+newTargetDirectory.getAbsolutePath());
performDirectoryExport(file, newTargetDirectory, sms);
continue;
}
}
download(file, new File(targetDirectory,getName(file.getPath())), sms);
}
}