我有一个功能,下载文件夹和子文件夹/文件从谷歌驱动器到我的电脑.但该功能一次只能下载一个文件/文件夹.我想在Google Drive上压缩它,然后下载它(就像当你下载一个文件夹或多个文件时,Google Drive的网络工作方式一样).有没有一种方法可以使用Google.drive.apis.v3来做到这一点?
下面是我使用C#编写的下载文件夹函数.
public void DownloadFolder(DriveService service, string folderId, string folderPath)
{
Directory.CreateDirectory(folderPath);
var fileListRequest = service.Files.List();
fileListRequest.Q = $"'{folderId}' in parents";
fileListRequest.Fields = "files(id, name, mimeType)";
var fileList = fileListRequest.Execute();
// Dowload file/Folder
foreach (var file in fileList.Files)
{
Container contain = new Container(file.Name, file.Id, file.MimeType, this.userName, this.location);
listOfFiles.Add(contain);
if (file.MimeType == "application/vnd.google-apps.folder")
{
// Recursive if obj(file) is a folder.
string subfolderPath = Path.Combine(folderPath, file.Name);
DownloadFolder(service, file.Id, subfolderPath);
}
else
{
// if obj(file) is a normal file, download.
string filePath = Path.Combine(folderPath, file.Name);
DownloadFile(service, file.Id, filePath);
}
}
}