如果文件夹不存在于Google云端硬盘中,请创建该文件夹 [英] Create folder if it does not exist in the Google Drive

查看:206
本文介绍了如果文件夹不存在于Google云端硬盘中,请创建该文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序适用于Google Drive Java API。



只有在Google云端硬盘根目录不存在的情况下,我才会在云端硬盘的根目录中创建文件夹。

  file = service.files()。insert(body).execute(); 

如何检查根文件夹中存在的文件夹。我只有文件夹名称'Myapp',而不是实例ID。

解决方案

 文件.List请求= service.files().list().setQ(
mimeType ='application / vnd.google-apps.folder'和trashed = false);
FileList files = request.execute();

您现在可以浏览文件中的所有文件夹,并检查是否有任何文件夹已搜索title。



不要忘记循环浏览所有页面:

  request.setPageToken(files.getNextPageToken()); 

编辑:

也许你可以查看此网站。您可以在搜索条件中添加标题,因此您不必检索所有文件夹。


My Application works with Google Drive Java API.

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();

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());

Edit:

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云端硬盘中,请创建该文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆