Skip to content

Instantly share code, notes, and snippets.

@haruiz
Last active July 20, 2019 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haruiz/939606ffe891add9616ba7bc0490bd20 to your computer and use it in GitHub Desktop.
Save haruiz/939606ffe891add9616ba7bc0490bd20 to your computer and use it in GitHub Desktop.
# Install the PyDrive wrapper & import libraries.
# This only needs to be done once per notebook.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# List .txt files in the root.
#
# Search query reference:
# https://developers.google.com/drive/v2/web/search-parameters
listed = drive.ListFile({'q': "title contains '.txt'"}).GetList()
for file in listed:
print('title {}, id {}'.format(file['title'], file['id']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment