PyDrive: cannot write file to specific GDrive folder

OK, looks like this is how you do it:

gfile = drive.CreateFile({'title':'dummy.csv', 'mimeType':'text/csv',
        "parents": [{"kind": "drive#fileLink","id": tgt_folder_id}]})

The "parents" map is used in the Google Drive SDK, which PyDrive is supposed to wrap. But the very few examples I've seen with PyDrive use "parent" and don't seem to work.

Anyway, hope this helps anybody else who hits the same problem.


Ahoj @i-am-nik, to list subfolders you may use slightly altered line:

file_list = drive.ListFile({'q': 'trashed=false', 'maxResults': 10}).GetList()
for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))

This way it will list both folders and subfolders (of course, if you have many files, you may need to change maxResults value or add narrowing query.