测试一个文件夹是否存在或不在谷歌驱动器 [英] test if a folder exist or not in google drive
问题描述
我想知道在Google Drive中是否存在文件夹(子文件夹),在搜索
在存在的方法中已经淡化在这种情况下
Dim result = req.Execute()
是我的方法是否正确?你能帮我吗?
您的代码有两个问题。
- 不正确的查询
您的行 req.Q =application / vnd .google-apps.folder
应该是
req.Q =mimeType ='应用程序/vnd.google-apps.folder'和name ='+ v +'和trashed = false
您可能需要整理引用和转义(即Don'复制/粘贴,并预计它第一次工作)
- 使用nextPageToken
该文件夹的存在不会由nextpageToken的存在来指示。相反,您需要检查响应中的文件数组是否包含> 0元素。
I want to know if folder (subfolder) exist in google drive or not , after searching in this page , i try to do it , i create a boolean function which return true if folder exist .
here is a code of boolean function
Public Function exist(v As String) As Boolean
Dim pag As String
Dim req = Service.Files.List()
req.Q = "application/vnd.google-apps.folder"
req.PageToken = pag
Dim result = req.Execute()
If (result.NextPageToken IsNot Nothing) Then
Return False
Else
Return True
End If
End Function
and here how i call it
If (exist(dat_sauv.SelectedItem) = False) Then
MessageBox.Show("folder exist")
End If
the exception is
exception has declenched in exist method in this insctruction
Dim result = req.Execute()
is my method correct or not ? can you help me
There are two problems with your code.
- Improper query
Your line req.Q = "application/vnd.google-apps.folder"
should be
req.Q = "mimeType='application/vnd.google-apps.folder' and name = '"+v+"' and trashed=false"
You'll probably need to tidy up the quoting and escaping (ie Don't copy/paste and expect it to work first time)
- use of nextPageToken
The presence of the folder will not be indicated by the presence of nextpageToken. Instead, you need to check the files array within the response for >0 elements.
这篇关于测试一个文件夹是否存在或不在谷歌驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!