Python google drive api将所有PDF上传到google drive
我正在使用pydrive将pdf文件上载到我的google drive文件夹。我想用此代码一次性发送本地文件夹中的所有Python google drive api将所有PDF上传到google drive,python,python-3.x,google-drive-api,google-api-dotnet-client,pydrive,Python,Python 3.x,Google Drive Api,Google Api Dotnet Client,Pydrive,我正在使用pydrive将pdf文件上载到我的google drive文件夹。我想用此代码一次性发送本地文件夹中的所有*pdf文件,但不确定从这里转到哪里?我应该使用glob?如果是的话,我想看一个例子 将1个文件发送到指定的google drive文件夹的工作代码: from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive gauth = GoogleAuth() gauth.LocalWebserve
*pdf
文件,但不确定从这里转到哪里?我应该使用glob
?如果是的话,我想看一个例子
将1个文件发送到指定的google drive文件夹的工作代码:
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()
你不能一次上传文件。使用API创建文件是一件简单的事情,而pydrive并没有一个以上的机制 你必须把它放在一个循环中,并在运行时上传每个文件
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
得到DalmTo-将使用循环尝试一些东西。感谢你的暗示。