Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python google drive api将所有PDF上传到google drive_Python_Python 3.x_Google Drive Api_Google Api Dotnet Client_Pydrive - Fatal编程技术网

Python google drive api将所有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

我正在使用pydrive将pdf文件上载到我的google drive文件夹。我想用此代码一次性发送本地文件夹中的所有
*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-将使用循环尝试一些东西。感谢你的暗示。