Skip to content
forked from zblack/GDTSC

Google Drive Trash Selective Cleaner

License

Notifications You must be signed in to change notification settings

stagnoman/GDTSC

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GOOGLE DRIVE TRASH SELECTIVE CLEANER

PURPOSE
When you delete a file on the client side of Google Drive it's not definitevely deleted but it goes in the Google Drive trash.
This behavior gives the opportunity to fetch previous versions or restore inadvertently deletions but it consumes Google Drive quota.
This is different from the versioning ability of Google Drive to retain all the versions of rewritten files at no cost (they are kept for 30 days).
Which one of the two cases depends on the application which writes the file:
- rewrite, no trashing and versioning
- deletion and writing of the new file, trashing
Usually when you save an existing file with the majority of applications the first case applies.
However if you have like me a lot of deletions you'll end up soon with a cluttered trash and an ever increasing consumed quota.
To get rid of this situation, you'll have either to tediously delete file by file or totally empty the trash and lose the history benefit.
I wrote this program to delete from trash the files matching user defined criteria.

INSTALLATION AND CONFIGURATION
- Download GDTSC.zip containing the program files and extract it in a local folder
- Activate the Google Drive API, going here: https://console.developers.google.com/project (you'll have to login with your gmail account)
- Create a project
- From the menu choose APIs & auth, APIs
- Find "Drive API" then click on the status button and switch it ON
- From the menu choose Credentials, then click on the CREATE NEW CLIENT ID button
- Download the authorization file clicking on Download JSON and put it in the same folder of the program
- Rename the downloaded file (client_secret_xxxxxxxxxxxxx.apps.googleusercontent.com.json) to "client_secret.json"
- The very first time you'll use the program, a browser should open asking you to authenticate and permit the application to communicate with google drive, do so.
In some circumstances you could get a browser error like this:
	Error:invalid_client
	Bad request.
	cookie_policy_enforce=false
	response_type=code
	scope=https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file
	access_type=offline
	redirect_uri=http://localhost:52147/authorize/
	client_id=AddYours.apps.googleusercontent.com
Should this happen you'll have to take these additional steps:
- From the API Console click on "Consent screen"
- Select your gmail address
- Enter a product name (ex: GDTSC)
- Press Save

USE
- Specify a date range of last modification, a range of file size and a substring of the file name (all the criteria must be matched), leaving defaults values will list all the trashed files before the last 30 days.
- Click on Search, after a while you'll be presented with a list of trashed files matching the criteria 
- Review the files list then press Remove to delete for good the visualized files from the trash.

NOTES
If your trash is very cluttered search and deletions operations will take time.
When deleting many files Google will take some time to actually free up your quota.
Sometime, while operating, Google servers reply with errors like "500 - Internal Server Error", this happens after 5 retry operations, so that case should mean a temporary service outage, anyway it's harmless.
During the tests this program could correctly delete about 10000 files, but it might still contains bugs.
Please have a fresh backup of your important data before using it.

BUILD
- VS >= 2010
- nuget
- Google.Apis.Drive.v2

About

Google Drive Trash Selective Cleaner

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%