Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create folder if it does not exist in the Google Drive

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.

like image 590
Fizer Khan Avatar asked Oct 10 '12 03:10

Fizer Khan


1 Answers

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.

like image 148
iixi Avatar answered Nov 04 '22 12:11

iixi