0

I am trying to make google drive file managing app in iOS. I am stuck because I want to search all files using any keyword and it should be display files and folder.Get all files and folder using this code.But if you search somthing, search only current file. Can you suggest me how to get subfiles and folder because it is display only single level not others.
-(void)getGDriveFilesAndFolders {

GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
if ([self.strPath length] == 0)
{
    query.q = @"'root' in parents";
}else{
    NSString *queryString = [NSString stringWithFormat:@"'%@' in parents",self.strPath];
    query.q=queryString;
}

[GoogleDriveViewController.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files,NSError *error)
 {
     if (error == nil)
     {
         [marrFiles removeAllObjects];

         NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
         [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];

         for(int i = 0; i < [files items].count; i++)
         {
             GTLDriveFile *driveFile = (GTLDriveFile*)[files itemAtIndex:i];
             if([driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"])
             {
                 if([driveFile.explicitlyTrashed intValue]!=1)
                 {
                     NSString *fileName = driveFile.title;
                     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                     [dict setValue:fileName forKey:[NSString stringWithFormat:@"Folder"]];
                     [dict setValue:driveFile.identifier forKey:@"objectId"];
                     [marrFiles addObject:dict];
                 }
             }
             else{
                 if([driveFile.explicitlyTrashed intValue] != 1)
                 {
                     NSString *fileName = driveFile.title;
                     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                     [dict setValue:fileName forKey:[NSString stringWithFormat:@"File"]];
                     long long int sizeData = [driveFile.fileSize intValue];
                     NSString *stringSize = [FileSizeClass stringSizeForFileWithBytes:[NSNumber numberWithLongLong:sizeData]];
                     GTLDateTime *modificationDate = (GTLDateTime*)driveFile.modifiedDate;
                     NSDate *date = [modificationDate date];
                     NSString *dateString = [dateFormatter stringFromDate:date];
                     dateString = [dateString createdTimeString];
                     NSString *stringInfo = [NSString stringWithFormat:@"%@ %@",stringSize,dateString];
                     [dict setValue:stringInfo forKey:[NSString stringWithFormat:@"Size"]];
                     [dict setValue:driveFile.identifier forKey:@"objectId"];
                     [dict setValue:driveFile.downloadUrl forKey:@"downloadUrl"];
                     [dict setValue:driveFile.fileSize forKey:@"FileSize"];

                     if(driveFile.webContentLink)
                     {
                         [dict setValue:driveFile.webContentLink forKey:@"webContentLink"];
                     }
                     [marrFiles addObject:dict];
                 }
             }
         }
         [tblGoogleDrive reloadData];
     } else {
         UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Message",nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
         [alertView show];
     }
     [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
 }];

}

Priya
  • 61
  • 4
  • 12
  • It's not clear what you are asking for. What do you want, and what is your code doing now? – Eric Koleda May 31 '14 at 00:27
  • This code is just list out files and folder into tableview. Using search display controller, It search only current files and folder which in tableview. I must be display files inside files. e.g folder1 -> f1.txt, f2.txt. Issue is when you search something, shown only current files or folder. when you search f1 then it displays not found. that means this code is for current files and folder not for sub files and subfolder. so,what should I do to get any files inside any place of it? – Priya Jun 02 '14 at 08:27

1 Answers1

0

Using a search query like 'folder id' in parents only searches that folder's direct children, not within sub-folders. There is no built-in way to search sub-folders, but you may be able to create a compound query where you search through each sub-folder explicitly, like 'folder' in parents or 'sub-folder1' in parents ...

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51