2

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
ancient
  • 23
  • 3

1 Answers1

1

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)
isAif
  • 2,126
  • 5
  • 22
  • 34
  • Thanks! I think this should suffice as an alternative, but would it also be possible to prompt the file explorer to load and use the GUI to specify a download location? – ancient Jul 06 '20 at 14:40
  • @ancient for that you need a GUI package for python like [tkinter](https://docs.python.org/3/library/tkinter.html). You can see following question for getting started on your requirement: https://stackoverflow.com/questions/3579568/choosing-a-file-in-python-with-simple-dialog – isAif Jul 06 '20 at 14:49