Specify file download location using PyDrive?

Viewed 344

I'm currently trying to download a file from Google Drive using PyDrive, but am only able to download the file to the same location as my Python program. Is there a way to specify the file's download location? This is how I am downloading files currently.

    if file1['title'] == file_name:
      file2 = drive.CreateFile({'id': file1['id']})
      print('Downloading file %s from Google Drive' % file2['title']) 
      file2.GetContentFile(file_name)  # Save Drive file as a local file
1 Answers

Try following:

if file1['title'] == file_name:
      location = "Path/where/you/want/to/save/"
      """
      if you are in linux and want to save it to documents try following
      location = "~/Documents/"
      the last forward slash i.e. '/' is important
      """

      full_path = location + file_name

      file2 = drive.CreateFile({'id': file1['id']})
      print('Downloading file %s from Google Drive' % file2['title']) 
      file2.GetContentFile(full_path)
Related