Exclude visibility of thrashed files while listing files in Google Drive

The Google Drive's API to list files includes thrashed files by default. To exclude thrashed files, we must use the thrashed=false query parameter. Reference: Method: files.list  |  Google Drive  |  Google for Developers

Following is the process to delete/thrash a file: Trash or delete files and folders  |  Google Drive  |  Google for Developers

If I delete a file, however, I still notice the file being returned in the list files response.

I would like to understand if there is any other way to exclude thrashed files in the list files response other than thrashing via the API.

0 3 1,020
3 REPLIES 3

What you do is to set a โ€œtrashedโ€ (note not thrashed) query term when you call the files.list API (the โ€œqโ€ parameter on the files.list documentation page). See https://developers.google.com/drive/api/guides/ref-search-terms for the reference for search terms. 

Hope that helps,

Ian

Thank you for your response @icrew.

However, as per my original comment, that's exactly what I have been doing. I have given multiple attempts at setting a trashed (thank you for the correction) query parameter to false while calling the files.list API with reference from Method: files.list  |  Google Drive  |  Google for Developers without avail. 

Deleted files don't seem to be marked at trashed somehow, it seems.

Hence, I was wondering if files can be trashed only via the trashing API as per Trash or delete files and folders  |  Google Drive  |  Google for Developers

Well, one way you might be able to learn more is to run some of these queries using the free, open source, command-line, indispensable GAM tool and have a look at exactly how it's doing what it does. Check out:

Specifically, what you can do is set GAM up to show you exactly what API calls it's making by following the instructions at https://github.com/GAM-team/GAM/wiki/GAM-options-files#seeing-http-api-calls-made-by-gam, then run the command:

gam user myuser@example.com print filelist excludetrashed

to see all the files owned by myuser that aren't in the trash. You could then see exactly the query that GAM is using to generate that list.

Hope that helps,

Ian