deleteDirectory method
Deletes the Directory with the Name of sDirectory
in the current directory.
Returns true
if the directory was deleted successfully
Returns false
if the directory could not be deleted or does not nexist
THIS USEFUL TO DELETE NON EMPTY DIRECTORY
Implementation
Future<bool> deleteDirectory(String sDirectory) async {
String currentDir = await this.currentDirectory();
if (!await this.changeDirectory(sDirectory)) {
throw FTPConnectException("Couldn't change directory to $sDirectory");
}
List<FTPEntry> dirContent = await this.listDirectoryContent();
await Future.forEach(dirContent, (FTPEntry entry) async {
if (entry.type == FTPEntryType.FILE) {
if (!await deleteFile(entry.name)) {
throw FTPConnectException("Couldn't delete file ${entry.name}");
}
} else {
if (!await deleteDirectory(entry.name)) {
throw FTPConnectException("Couldn't delete folder ${entry.name}");
}
}
});
await this.changeDirectory(currentDir);
return await deleteEmptyDirectory(sDirectory);
}