我有一个功能,下载文件夹和子文件夹/文件从谷歌驱动器到我的电脑.但该功能一次只能下载一个文件/文件夹.我想在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);
        }
    }
}

推荐答案

Google Drive API不提供一次下载一个文件然后在本地压缩文件所需功能

Csharp相关问答推荐

如何使嵌套for-loop更高效?

Plotly.NET访问互联网时出现异常

有没有办法把+02:00转换成TimeSpan?""

如何注册实现同一接口的多个服务并注入到控制器构造函数中

(乌龙)1&#比c#中的UL&#慢吗?

如何在实体框架中添加包含列表?

如何在ASP.NET Core8中启用REST应用程序的序列化?

为什么无法将对象转换为泛型类型

异步任务导致内存泄漏

try 在.Net核心身份注册页面中使用AJAX,但没有成功..NET Core 5.0 Razor页面应用程序

如何将字符串变量传递给JObject C#-无法加载文件或程序集';System.Text.Json

如何将MemberInitExpression添加到绑定中其他Lambda MemberInitExpression

使用C#和.NET 7.0无法访问Cookie中的数据

Azure Functions v4中的Serilog控制台主题

如何让游戏对象在切换场景时被销毁,但在开始新游戏时重新锁定

用于ASP.NET核心的最小扩展坞

C#命名管道-编码错误?

我应该为C#12中的主构造函数参数创建私有属性吗?

如何在.NET MAUI上在iOS和Mac之间共享代码?(no条件编译和无代码重复)

反序列化我以前使用System.Text.Json序列化的文件时出现异常