I'm using PyDrive (http://pythonhosted.org/PyDrive/) to simplify API access to the Google Drive, but have hit a stumbling block when attempting to delete an existing file from Drive. I saw no clear way from the documentation or from a brief skim of the source code. Could somebody point me in the right direction. Cheers.
2 Answers
UPDATE: This functionality has been merged. You can now call fi.Delete()
or fi.Trash()
. See the docs for more details.
5-line codes are added in files.py in PyDrive folder for delete-function.
You can download the updated files.py from:
https://github.com/ytakefuji/PyDrive/blob/master/files.py
you have to compile to generate files.pyc
$ cat help.py
import py_compile
py_compile.compile("files.py")
$ python help.py
example: deleting a file on Google Drive through oauth2:
https://github.com/ytakefuji/PyDrive/blob/master/oauth2_delete.py
EDIT: The lines in question are (added to GoogleDriveFile class):
def DeleteFile(self,file_id):
try:
self.auth.service.files().delete(fileId=file_id).execute()
except errors.HttpError, error:
print 'An error occurred: %s' % error
Documentation of this functionality can be found here.

- 2,170
- 1
- 21
- 26

- 31
- 2
-
1In addition to the github link, would you be able to provide the relevant part of the diff inlined here, and explained? – EyasSH May 05 '15 at 02:12
-
Last 5 lines are added in files.py – yoshiyasu takefuji May 05 '15 at 07:03
Scott Blevins coded it, but his code as never been merged. It looks like pydrive is kind of abandoned. Too bad as it is quite useful.
Simply download the zip file from here and replace the old pydrive code with its content: https://github.com/smeggingsmegger/PyDrive/tree/Trash_and_Delete

- 11
-
Good find. Yeah it was a useful little library, shame that development seems to have ceased. Thanks for sharing your findings. – Pike Aug 15 '14 at 13:34