如果 Google Drive 中不存在文件夹,请创建该文件夹

Create folder if it does not exist in the Google Drive(如果 Google Drive 中不存在文件夹,请创建该文件夹)
本文介绍了如果 Google Drive 中不存在文件夹,请创建该文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的应用程序使用 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 中不存在文件夹,请创建该文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)