不指定目标文件名的Python Google驱动器文件下载

时间:2018-10-18 18:10:49

标签: python-3.x google-drive-api pydrive

我正在尝试从Google驱动器下载文件ID为文件的文件,然后将其放置在我的本地文件夹中。下载工作正常,但是我的问题是,当我尝试指定文件夹和文件名时,可以手动指定文件名,但不能自动指定文件名。我的意思是我希望从googledrive获取的文件名应该自动进入我指定的文件夹中,而无需任何手动输入作为文件名。这是我的代码:

#!/usr/bin/python3
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
    # Refresh them if expired
    gauth.Refresh()
else:
    # Initialize the saved creds
    gauth.Authorize()
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")
drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'id':'xxx'})
file1.GetContentFile('/home/smc/sw_files/xxx.zip')

1 个答案:

答案 0 :(得分:0)

Desktop.getDesktop().open()

这可能对您有帮助!