pushFolder method

Stream<FolderTransferProgress> pushFolder(
  1. Directory directory,
  2. String destinationDirectory
)

Copies a local filesystem folder to Google Drive. Mimetypes are interpreted from the files Specify a destinationDirectory to use. Cannot copy to root of drive.

Implementation

Stream<FolderTransferProgress> pushFolder(final Directory directory, final String destinationDirectory) async* {
  int fileCount = 0;
  final rootPath = directory.path;

  final totalFileCount = await directory.list(recursive: true).length;

  await for (final file in directory.list(recursive: true).where((event) => event.statSync().type == FileSystemEntityType.file)) {
    fileCount++;
    final remotePath = '$destinationDirectory/${file.path.substring(rootPath.length)}';
    yield FolderTransferProgress(FolderPushStatus.sending, path: file.path, copiedFiles: fileCount, totalCount: totalFileCount);
    // todo keep track of folders we have already created, so we don't recheck these folders needlessly
    await pushFile(File(file.path), remotePath);
  }
  yield FolderTransferProgress(FolderPushStatus.completed);
}