본문 바로가기

IT/Python

구글드라이브 휴지통비우기

 

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
my_drive = GoogleDrive(gauth)
while True:
  for a_file in my_drive.ListFile({'q': "trashed = true"}).GetList():
      # print the name of the file being deleted.
      print('delete ' + a_file['title'])
      # delete the file permanently.
      a_file.Delete()

Reference : https://stackoverflow.com/questions/53028607/how-to-remove-the-file-from-trash-in-drive-in-colab