Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 子文件夹google drive中的现有文件_Vb.net_File_Google Drive Api_Exists - Fatal编程技术网

Vb.net 子文件夹google drive中的现有文件

Vb.net 子文件夹google drive中的现有文件,vb.net,file,google-drive-api,exists,Vb.net,File,Google Drive Api,Exists,我想用vb.net验证google drive中是否存在文件,文件路径在子文件夹中。我创建existfile方法,在其中列出子文件夹和列表文件并使用测试,但总是countfile=0。 这是existfile方法代码 Public Function existfile(v As String) As String Dim page As String = "" Dim req = Service.Files.List() req.Q = "mimeType = 'app

我想用vb.net验证google drive中是否存在文件,文件路径在子文件夹中。我创建existfile方法,在其中列出子文件夹和列表文件并使用测试,但总是countfile=0。 这是existfile方法代码

 Public Function existfile(v As String) As String
    Dim page As String = ""
    Dim req = Service.Files.List()
    req.Q = "mimeType = 'application/vnd.google-apps.file' and trashed = false "
    req.Spaces = "drive"
    req.Fields = "nextPageToken, items(id, title)"
    req.PageToken = page
    Dim result = req.Execute()
    ' sous doc
    Dim ref = Service.Files.List()
    ref.Q = "mimeType = 'application/vnd.google-apps.folder' and trashed = false "
    Dim fo = ref.Execute()

    'récuprer la reference (ID) du dossier existant , sinon la fonction retourne false en cas d'inexistance'
    Const a As String = "false"
    For Each listf In fo.Items
        For Each test In result.Items
            If (test.Title = v) Then
                Return (test.Id)
            End If
        Next
    Next
    Return (a)
End Function
第一个用于列表文件夹,第二个用于列表文件,但result.item始终为0


文件路径在subfolder下,子文件夹在bigfolder下

您可能需要选中此选项,它用于列出Google驱动器上的文件

// Define parameters of request.
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name)";

// List files.
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
        .Files;
Console.WriteLine("Files:");
if (files != null && files.Count > 0)
{
    foreach (var file in files)
    {
            Console.WriteLine("{0} ({1})", file.Name, file.Id);
    }
}
else
{
    Console.WriteLine("No files found.");
}
Console.Read();
//定义请求的参数。
fileResource.ListRequest ListRequest=service.Files.List();
listRequest.PageSize=10;
listRequest.Fields=“nextPageToken,files(id,name)”;
//列出文件。
IList files=listRequest.Execute()
.档案;
Console.WriteLine(“文件:”);
if(files!=null&&files.Count>0)
{
foreach(文件中的var文件)
{
Console.WriteLine(“{0}({1})”,file.Name,file.Id);
}
}
其他的
{
WriteLine(“未找到任何文件”);
}
Console.Read();

其他参考资料:

谢谢,您的代码在google drive中搜索的文件不在文件夹或子文件夹中(我的意思是搜索结果总是找不到文件)。我找到了一个解决方案,我使用了2个foreach,第一个用于列出驱动器中存在的所有文件夹,第二个用于列出文件夹中存在的所有文件,然后我使用了if测试,结果它正常工作。