問題描述
我的應用程序使用 Google Drive Java API.
My Application works with Google Drive Java API.
我只想在 Google Drive 的根目錄中創建文件夾,前提是它不存在.我正在使用下面的代碼來創建文件夾.
I want to create folder in the root of the Google Drive only if it does not exist. I am using below code to creat folder.
file = service.files().insert(body).execute();
如何檢查根文件夾中的文件夾是否存在.我只有文件夾名稱Myapp",沒有實例 ID.
How do i check the folder existance in the root folder. I have only the folder name 'Myapp', not the instance ID.
推薦答案
Files.List request = service.files().list().setQ(
"mimeType='application/vnd.google-apps.folder' and trashed=false");
FileList files = request.execute();
您現在可以瀏覽文件"中的所有文件夾并檢查是否有任何文件夾具有搜索的標題.
You could now go through all folders in "files" and check if any of the folders have the searched title.
不要忘記遍歷所有頁面:
Don't forget to loop through all pages with:
request.setPageToken(files.getNextPageToken());
也許你可以看看這個網站.您可以在搜索條件中添加標題,這樣您就不必檢索所有文件夾.
Maybe you could have a look at this site. You can add the title in your search criteria instead so you do not have to retrieve all the folders.
這篇關于如果 Google Drive 中不存在文件夾,請創建該文件夾的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!