简体   繁体   English

如何列出特定文件夹内的文件夹和文件

[英]How to list folders and files inside a specific folder

I have some queries regarding the google drive api. 我对Google Drive API有一些疑问。 I am following the code from here( https://everyday-be-coding.blogspot.com/ ) 我正在从这里关注代码( https://everyday-be-coding.blogspot.com/

  1. How to change default file list length(100) to full file list length from the google drive ? 如何更改默认文件列表长度(100)从谷歌驱动器的完整文件列表长度?
  2. How to avoid listing of file from the trash of google drive? 如何避免从Google Drive的垃圾箱中列出文件?
  3. How to search and list out the content inside a specific folder with a folder name in the google drive? 如何在Google驱动器中使用文件夹名称搜索和列出特定文件夹内的内容?

These are the issues are i am facing on with google drive api.Please help me out from these issues. 这些是我在使用Google Drive API时遇到的问题。请帮助我解决这些问题。

This is the code i am using to list the files 这是我用来列出文件的代码

 public static List<GoogleDriveFiles> GetDriveFiles()
    {
        DriveService service = GetService();

        // Define parameters of request.

        FilesResource.ListRequest FileListRequest = service.Files.List();
        FileListRequest.Q = "mimeType = 'application/vnd.google-apps.folder'";

        FileListRequest.Fields = "nextPageToken, files(id, name, size, version, trashed, createdTime)";

        // List files.
        IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files.Where(c => c.Trashed == false).ToList();
        List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>();

        if (files != null && files.Count > 0)
        {
            foreach (var file in files)
            {
                GoogleDriveFiles File = new GoogleDriveFiles
                {
                    Id = file.Id,
                    Name = file.Name,
                    Size = file.Size,
                    Version = file.Version,
                    CreatedTime = file.CreatedTime
                };
                FileList.Add(File);
            }
        }
        return FileList;
    }

How to change default file list length(100) to full file list length from the google drive ? 如何更改默认文件列表长度(100)从谷歌驱动器的完整文件列表长度?

files.list as a default max page size of 100 but you can increase that by sending the pageSize parameter you can set it between 100 - 1000. files.list的默认最大页面大小为100,但是您可以通过发送pageSize参数来增加它的大小,可以将其设置为100-1000。

After that you will need to use the NextPageToken. 之后,您将需要使用NextPageToken。 You are in luck in that we have a PageStreamer method for this in C# 真幸运,我们在C#中有一个PageStreamer方法

var pageStreamer = new Google.Apis.Requests.PageStreamer<Google.Apis.Drive.v3.Data.File, FilesResource.ListRequest, Google.Apis.Drive.v3.Data.FileList, string>(
                                                   (req, token) => request.PageToken = token,
                                                   response => response.NextPageToken,
                                                   response => response.Files);

I have a tutorial on how to use it here https://www.daimto.com/list-all-files-on-google-drive/ 我在这里有一个如何使用它的教程https://www.daimto.com/list-all-files-on-google-drive/

How to avoid listing of file from the trash of google drive? 如何避免从Google Drive的垃圾箱中列出文件?

File.list has another paramater called the q paramater which will allow you to search for the files you are looking for search 拥有的File.List称为第q paramater另一paramater这将允许你搜索你要找的文件搜索

so the following would ignore trashed files. 因此以下内容将忽略已删除的文件。

q = trashed = false

How to search and list out the content inside a specific folder with a folder name in the google drive? 如何在Google驱动器中使用文件夹名称搜索和列出特定文件夹内的内容?

To do this you will need to find the folder you are looking for the eastest way to do that would be to again use the q paramater and search for only folders with the name will help you find the folder you are looking for. 为此,您将需要找到您要查找的最东部的文件夹,方法是再次使用q参数,并且仅搜索具有该名称的文件夹将有助于您找到所需的文件夹。

mimeType != 'application/vnd.google-apps.folder' and name = 'hello'

Once you have it save the file.id for that folder 保存后,保存该文件夹的file.id

mimeType != 'application/vnd.google-apps.folder' and name = 'hello'

Then you can make another request which will find all of the files in a parent folder 然后,您可以发出另一个请求,该请求将找到父文件夹中的所有文件

'the file id here' in parents

The best place to test your searches is in the try me on the documentation page here 测试您的搜索的最佳地点是在此处的文档页面上尝试我

My tutorials Search files on Google Drive with C# 我的教程使用C#在Google云端硬盘上搜索文件

  1. There is no file listing limit in Google Drive, you can use the nextPage parameter and it will continue in another page when it reaches 100 files. Google云端硬盘中没有文件列表限制,您可以使用nextPage参数,当它达到100个文件时,它将在另一个页面中继续。
  2. You can avoid listing the files in Trash by using the query trashed = false . 您可以避免使用查询 trashed = false列出“已删除邮件”中的文件。
  3. To search files in a folder, you need the folder Id and the search query 'folder id' in parents . 要搜索文件夹中的文件,您需要文件夹ID和'folder id' in parents的搜索查询'folder id' in parents

Hope this helps! 希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何读取特定SkyDrive文件夹中的文件列表? - How to read the list of files in a specific SkyDrive folder? Rackspace CloudFiles C#API:如何在根“文件夹”中列出文件,以及如何在“文件夹”中列出(子)文件夹? - Rackspace CloudFiles C# API: How to list files on root 'folder', and how to list (sub)folders within a 'folder'? 如何使用里面的文件返回我的文件夹列表? - How do I return a list of my folders with the files inside? 如何将文件夹内的文件列出到表单并从那里启动它? - How to list files inside a folder to a form and launch it from there? 有没有办法获取文件夹中不包括特定文件夹的路径列表 - Is there a way to get a list of paths in a folder excluding specific folders 如何在 MicrosoftGraph Query 中获取文件夹和文件以及内部文件夹或文件 - how to Get the Folder and Files and Inner Folders or Files in MicrosoftGraph Query 获取特定 Netsuite 文件夹中的文件列表 - Get list of files in a specific Netsuite folder 如何以IEnumerable而不是数组的形式获取文件/文件夹列表 - how to get a list of files / folders as an IEnumerable and not an array 如何获取子目录中的文件和文件夹列表 - How to get a list of files and folders in the subdirectory 如何将文件从文件夹和子文件夹传输到 C# 中由文件名模式创建的特定文件夹(File2specific Folders) - How to transfer files form folders and sub-folders to specific folders created by file name pattern in C# (File2specific Folders)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM