我有一个文档列表及其路径。
Unsigned/Corporate Tax Return/Testing.docx
Signed/Report/fieldsInfo.pdf
Unsigned/Corporate Tax Return/testSecure.pdf
Unsigned/Corporate Tax Return/2012/fileCatcher.pdf
Unsigned/Corporate Tax Return/2012/taxReturn.pdf
从这里我想要一个树结构的对象数组,所有这些对象都放在其中。我有两种对象类型:文档和文件
我将如何在目标 C 中执行此操作?
到目前为止我所拥有的:
- (void) createFolderStructure:(Document *) doc{
Folder * root = [[Folder alloc]init];
NSArray * folders = [doc.documentFilePath componentsSeparatedByString:@"/"];
for(NSString * folderName in folders){
if([root.folderSubFolders count] == 0){
//root is empty , create folder
Folder * newFolder = [[Folder alloc]init];
newFolder.folderName = folderName;
[root.folderSubFolders addObject:newFolder];
} else {
//root has subfolders
for(Folder * folder in root.folderSubFolders){
if ([folder.folderName isEqualToString:folderName]) {
//folder exists in subfolders
} else {
//folder doesn't exist ,create folder
Folder * newFolder = [[Folder alloc]init];
newFolder.folderName = folderName;
[root.folderSubFolders addObject:newFolder];
}
}
}
}
}