1
votes

I am using the pydrive to upload pdf files to my google drive folder. I am wanting to send all *pdf files in a local folder at once with this code but not sure where to go from here? Should I use glob? If so I would like to see an example, please.

working code that sends 1 file to the designated google drive folder:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(g_login)

folder_id = 'google_drive_id_goes_here'
f = drive.CreateFile({'title': 'testing_pdf',
                      'mimeType': 'application/pdf',
                      'parents': [{'kind': 'drive#fileLink', 'id':folder_id}]})
f.SetContentFile('/Users/Documents/python/google_drive/testing.pdf')
f.Upload()
1

1 Answers

0
votes

You cant upload files at once. Create file with the API is a single thing and pydrive as no mechanism for uploading more then one .

Your going to have to put this in a loop and upload each file as you go.

import os
directory = 'the/directory/you/want/to/use'

for filename in os.listdir(directory):
    if filename.endswith(".txt"):
        f = open(filename)
        lines = f.read()
        print (lines[10])
        continue
    else:
    continue