Vinay Dev
Vinay Dev

Reputation: 33

Google Drive API: I have to fetch only files in that folder without trashed files

I am trying to get a list of files in a folder on Google drive using the Google drive API. When I make my request I am getting a list of child elements in that folder including previous deleted files.

How do I get only the files that are in the folder without the ones that have been deleted or trashed?

Upvotes: 3

Views: 2566

Answers (2)

Vinay Dev
Vinay Dev

Reputation: 33

I found the issue and i added this piece of code to resolve the issue,

Google.Apis.Drive.v2.Data.File fileDetails = new Google.Apis.Drive.v2.Data.File();
 try
 {
    fileDetails = service.Files.Get(fileId).Fetch();
   //check whether files is in thrash and ignore if any
    if (fileDetails.Labels.Trashed.GetValueOrDefault())
     {
          return null;
     }

  }

Upvotes: 0

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116869

I don't think you are seeing deleted files. Deleted files are permanently deleted. I think you are seeing trashed files which are like putting files in the trash can on windows, they are removed but not really gone.

You want to add a search parameter to your files.list request. you want to tell it to not include trashed.

trashed = false

Upvotes: 4

Related Questions