Coder Social home page Coder Social logo

google-drive-cleaner's Introduction

google-drive-cleaner

Google Drive is an excellent way to share files with colleagues and friends. However, it makes some unconventional assumptions about the organization of files and folders. As a result of these assumptions (and sequences of events like the ones documented here, some users will find that they have "orphaned" files. These files are included in "All Files" but not visible in any other folder on My Drive. They continue to consume quota and the "all files" technique is impractical for large numbers of files.

This Python package addresses the orphaned files problem by scanning through Google Drive and find orphaned files. Once identified, they can be moved into a folder for manual review (recommended) or directly into the trash.

Google API Code

The following were the steps I took to get the Google API configured:

  • Go to the APIs console at https://code.google.com/apis/console
  • Create a project (no need to change the ID)
  • It will take a minute or so for the project to finish then you should be redirected to the project hompage
  • Under "APIs & Auth" click on APIs
    • Turn on Drive API and Drive SDK (I turned off the rest)
  • Under "APIs & Auth" click on Consent screen
    • (VERY IMPORTANT) Enter a Product Name and save the page. You'll get hard-to-diagnose auth errors if you fail to do this.
  • Under "APIs & Auth" click on Credentials
    • Under the OAuth Section click "Create new Client ID"
    • Make sure you choose "Installed application" and "Other"
    • Clicking create should present you to the two pieces of data you need
    • Copy those values into config.py

Use (to assist non-programmers)

WARNING: This procedure is provided is provided "as is" without express or implied warranty. The Google API includes commands that could result in the loss of data. While the author believes the guide to be accurate, any number of things (including the Google API) could have changed since it was written. If you elect to follow this guide, you take full responsibility for the consequences. If you live in a country where the author cannot disclaim such a warranty, you are not licensed to use the following procedure.

  • Install Python
  • Install pip (http://pip.readthedocs.org/en/latest/installing.html)
  • Install the Google API by running "pip install --upgrade google-api-python-client"
  • Install another required library by runnign "pip install httplib2"
  • Using a command prompt, change directory into the folder that contains cleaner.py
  • Start python. In the python console (once you see >>>), run:
from cleaner import *
dc = build_connection()

This second command will prompt you to go to a URL in your browser and complete an authorization process. Copy the string provided by Google and paste it back into the python console. Pressing enter should complete the process successfully and you should see python loading all your files.

While the original author designed this to delete orphaned files, I strongly recommend that you create a folder (named something like "_delete") and move all your orphaned files/folders to this directory. This will give you a chance to visually review all the files before deleting (and you can always delete the whole folder if that's what you really want to do).

To move files, navigate to the target Google Drive folder in your web browser. The URL will end in something like "folders/0B1Bdl-YbgK8ZUWx0cVEtTklWdUU". Everything after the '/' is the ID of the folder. Using that ID, run the following substituting the ID for . In the final command, the ID should be enclosed in quotes:

dc.moveItems("<folder id>")

google-drive-cleaner's People

Contributors

claytondaley avatar zpm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.