[英]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/ )
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云端硬盘上搜索文件
trashed = false
. trashed = false
列出“已删除邮件”中的文件。 'folder id' in parents
. 'folder id' in parents
的搜索查询'folder id' in parents
。 Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.