我正在尝试在iOS中制作谷歌驱动器文件管理应用程序。我被困了,因为我想使用任何关键字搜索所有文件,它应该是显示文件和文件夹。使用此代码获取所有文件和文件夹。但是如果搜索某些内容,则只搜索当前文件。你能建议我如何获得子文件和文件夹,因为它只显示单一级别而不显示其他文件 - (无效)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];
}];
}
答案 0 :(得分:0)
使用'folder id' in parents
之类的搜索查询只会搜索该文件夹的直接子项,而不会搜索子文件夹中的子项。搜索子文件夹没有内置方法,但您可以创建一个复合查询,您可以在其中明确搜索每个子文件夹,例如'folder' in parents or 'sub-folder1' in parents ...