0

The Google Drive API includes a special hidden folder that your app can use to store application specific data.

Here's the tutorial: Storing Application Data

I insert the file into the hidden folder with this method:

    private static File insertFileInApplicationDataFolder(Drive service, String title, String description,
        String mimeType, String filename) {
    // File's metadata.
    File body = new File();
    body.setTitle(title);
    body.setDescription(description);
    body.setMimeType(mimeType);
    body.setParents(Arrays.asList(new ParentReference().setId("appfolder")));

    // File's content.
    java.io.File fileContent = new java.io.File(filename);
    FileContent mediaContent = new FileContent(mimeType, fileContent);
    try {
        File file = service.files().insert(body, mediaContent).execute();
        return file;
    } catch (IOException e) {
        System.out.println("An error occured: " + e);
        return null;
    }
}

Now, I want to delete all files that are into the folder.

I tried with service.files().get("appfolder").execute().clear();, but it doesn't work. The files remain there.

Dave
  • 1,428
  • 4
  • 31
  • 49
  • You can find how to delete files here: http://stackoverflow.com/a/35143284/2780428. Notice if you want to delete multiple files, you can put the delete actions in a batch and then execute the batch. – Alic Jun 09 '16 at 20:50

1 Answers1

0

The link you posted refers to the Android API (GDAA) but your code is using the REST API. Make sure you understand the difference.

"appfolder" is simply an alias for a folder. You can use it like any regular folder, so eg. you can list its children and delete them.

Out of curiosity, what is the "clear()" method you're calling? I've never seen that documented.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • how do you know that I'm using REST API? I don't know the difference. What is? Sorry, I made a mistake when I copied and pasted. I meant that with **service.files().get("appfolder")** I access to dir, but I don't know how to delete the files inside it. I didn't found none examples – Dave Jul 30 '15 at 15:30