drive api: list files in trash bin

Is there any way to only list the trashed files? For my current project, I just need to know if the trash bin empty or not.

note: I'm using python 3 and drive API v2 with PyDrive

Thanks for your attention.Hope you will try to help me.

Upvotes: 0

Views: 902

Answers (1)

Tanaike
Tanaike

Reputation: 201378

I believe your goal as follows.

  • You want to check whether there are the trashed files.
  • You want to achieve this using pydrive of python.

In this case, how about using ListFile method with the search query of trashed=true? By this, when the returned value has the values, it indicates that the trashed files are existing. When this is reflected to a sample script, it becomes as follows.

Sample script:

drive = GoogleDrive(auth) # Please use your "auth".

res = drive.ListFile({'q': "trashed=true"}).GetList()
if not res:
    print("No trashed files.")
else:
    print("Trashed files are found.")

References:

Upvotes: 1

Related Questions