0

I've been trying to apply the solution described here, adapting from the PyDrive documentation. What I want is to work on files in a specific folder, not get a list of all files in my Drive (which contains thousands). So I've tried:

files = drive.ListFile({'q': "'myfolder' in parents"}).GetList()

where myfolder is the name of the folder I want to get this list from. However, this returns an HTTP 404 error. Replacing myfolder with root works (per Google's example), but take ages (so my syntax is correct, but I probably misunderstand what parents represents).

Can anyone help?

mrgou
  • 1,576
  • 2
  • 21
  • 45
  • So you are interested in listing all the files (children) of a folder am I right? Maybe using ```children.list()``` would solve your question, check out a simple implementation of it [here](https://developers.google.com/drive/api/v2/reference/children/list#examples) and its [documentation](https://developers.google.com/drive/api/v2/reference/children/list) and let me know if this solved your issue for formalising it into an answer :D – Mateo Randwolf Apr 17 '20 at 10:29
  • Mmmmh... I guess that could work, but I would have hoped for getting a list of [`GoogleDriveFile`](https://pythonhosted.org/PyDrive/pydrive.html#pydrive.files.GoogleDriveFile) objects from which I can then grab the shareable link directly... – mrgou Apr 17 '20 at 11:59

1 Answers1

1

I actually was nearly there: I needed to pass the folder ID instead of the name in the query:

files = drive.ListFile({'q': "'folder_id' in parents"}).GetList()

From there, I get a collection of dictionaries from which it's easy to get the file name (title key) and shareable link (alternateLink).

mrgou
  • 1,576
  • 2
  • 21
  • 45