我正在尝试将文件上传到我的Google驱动器,下面的代码有效。 如何指定要上传到即驱动器的文件夹-与我共享的文件夹-csvFolder
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
file2 = drive.CreateFile()
file2.SetContentFile('new_test.csv')
file2.Upload()
答案 0 :(得分:2)
如果我的理解是正确的,那么该修改如何?
file2 = drive.CreateFile()
file2 = drive.CreateFile({'parents': [{'id': '### folder ID ###'}]})
如果这不是您想要的结果,我表示歉意。
要从文件夹名称将文件上传到特定文件夹时,该修改如何?
file2 = drive.CreateFile()
file2.SetContentFile('new_test.csv')
file2.Upload()
folderName = '###' # Please set the folder name.
folders = drive.ListFile(
{'q': "title='" + folderName + "' and mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()
for folder in folders:
if folder['title'] == folderName:
file2 = drive.CreateFile({'parents': [{'id': folder['id']}]})
file2.SetContentFile('new_test.csv')
file2.Upload()