使用以下方法,我能够获取子文件夹,但此代码从根目录检索所有文件夹。例如,如果垃圾箱中有一个文件夹,它也会检索该文件夹以及“我的驱动器”中的文件夹。
我的要求是,如果我的驱动器中没有该文件夹,那么首先我应该创建一个然后插入文件。我的问题是,当我检查文件夹名称时,由于文件夹存在于垃圾箱中但不在我的云端硬盘中,因此我在文件夹存在时收到响应。
这是我检索文件夹的方法。
如果有人有任何想法,请告诉我。
-(void)getFileListFromSpecifiedParentFolder {
GTLQueryDrive *query2 = [GTLQueryDrive queryForFilesList];
// GTLQueryDrive *query2 = [GTLQueryDrive queryForChildrenListWithFolderId:@"My Drive"];
query2.q = @"";
//or i also use this code
query2.q = @"mimeType = 'application/vnd.google-apps.folder'";
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query2
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveChildList *children, NSError *error) {
NSLog(@"\nGoogle Drive: file count in the folder: %d", children.items.count);
//incase there is no files under this folder then we can avoid the fetching process
if (!children.items.count) {
return ;
}
if (error == nil) {
for (GTLDriveChildReference *child in children) {
GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:child.identifier];
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *file,
NSError *error) {
NSLog(@"\nfile name = %@ \n file kind %@ \n file identifier %@", file.title,file.kind,file.identifier);
}];
}
}
else
[self createFolderForGoogleDriveWithName:@"Music"];
}];
}