2

My application is based on a tree-structure with a known root-folder (say 'theFolder') .
I'm able to retrieve all folders whose name is <theFolder>:

gapi.client.request(
    {
    'path': '/drive/v2/files',
    'method': 'GET',
    'params': {
        q : "title='"+theFolder+"' and mimeType='application/vnd.google-apps.folder'",
        fields: "items(description,id,modifiedDate,parents/id,title)"
        },
    callback: theCallback
    });

But, as I want only the root folder (if any), I tried in vain to add some criteria:

  • and parents.isRoot
  • and parents.isRoot=true
  • and parents/isRoot=true
  • and (isRoot in parents)

I understand this is related to the Getting a list of files by folder on Drive SDK and more generally to: "how to set criteria on sub-fields?"

Community
  • 1
  • 1
Pierre
  • 261
  • 3
  • 12
  • What do you mean by root folder. Do you mean the rot folder (in which case it's usually called "My Drive") or do you mean folders with no parents? (only some shared folders are like that) – Nicolas Garnier Jul 19 '12 at 12:42
  • @Nivco: "My" root folder is the highest folder in the hierarchy of folders and files, created by an application - where files and folders are simply instanciations of other objects. With Google-Drive this means a file created with a special mimeType and without setting its `parents.id`. There is an interesting side-effect: its metadata `parent.isRoot` is set to true. – Pierre Jul 19 '12 at 15:36
  • Ah OK, what you mean is that you want to fetch the folders that have the root folder as a parent :) I got confused because of shared folders that can be "real" root folders (a root has no parents) yours are childs of the root folder. I've updated the response below. Let me know if that works – Nicolas Garnier Jul 19 '12 at 22:17
  • This `'root' in parents` sounds great! Looks like `'folderID' in parents` as described in [Getting a list of files by folder on Drive SDK](http://stackoverflow.com/q/11400669/1530236) – Pierre Jul 19 '12 at 22:36

1 Answers1

2

You should be able to check that the root folder is in the parents of the folders you are looking for. For this you can use the 'root' alias for that folder.

try this in your search query:

'root' in parents
Nicolas Garnier
  • 12,134
  • 2
  • 42
  • 39
  • I'd like to avoid these unnecessary loops and bandwidth loads. But for the moment I think it's better to check, for each returned `items`, whether its metadata `parent.isRoot` is set to true. This is just a workaround - for the moment... – Pierre Jul 19 '12 at 16:00
  • Well it;s a good feature request. Not sure we keep an index on this criteria but if so, we could expose it. I'll file the feature request internally. – Nicolas Garnier Jul 19 '12 at 18:47
  • Thanks a lot. Maybe something like "How to set criteria on sub-fields in the query parameter?" could be more successful... – Pierre Jul 19 '12 at 18:59
  • Works fine! Unfortunately, I can't "vote up" (requires 15 reputation) – Pierre Jul 19 '12 at 22:44