주어진 시작 경로에서 파일 시스템의 구조를 모델링하려고합니다. 목표는 해당 경로에서 파일 시스템의 표준 NSOutlineView
을 작성하는 것입니다.NSDirectoryEnumerator를 사용하여 파일 시스템 모델하기
fileSystemItem
이라는 모델 개체가 있습니다. ;
childrenItems
(다른 fileSystemItems
의 배열)fileSystemItem
객체 점)
parentItem
을isLeaf
(폴더NO
파일YES
) : 그것은 다음 (매우 표준) 관계와 속성이 있습니다fullPath
(NSString
, 객체 파일 경로)
제 질문은 : NSDirectoryEnumerator
을 사용하여 모델을 어떻게 작성합니까? 나는이 작업을 수행 할 경우
// NOTE: can't do "while (file = [dirEnum nextObject]) {...} because that sets
// file to an auto-released string that doesn't get released until after ALL
// iterations of the loop are complete. For large directories, that means our
// memory use spikes to hundreds of MBs. So we do this instead to ensure that
// the "file" string is released at the end of each iteration and our overall
// memory footprint stays low.
NSDirectoryEnumerator *dirEnum = [aFileManager enumeratorAtPath:someStartingPath];
BOOL keepRunning = YES;
while (keepRunning)
{
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
NSString *file = [dirEnum nextObject];
if (file == nil) break;
// ... examine "file". Create a fileSystemItem object to represent this item.
// If it's a folder, we need to create a fileSystemItem for each item in the folder
// and each fileSystemItem's "parentItem" relationship needs to be set to the
// fileSystemItem we're creating right here for "file." How can I do this inside
// the directoryEnumerator, because as soon as we go to the next iteration of the
// loop (to handle the first item in "file" if "file" is a folder), we lose the
// reference to the fileSystemItem we created in THIS iteration of the loop for
// "file". Hopefully that makes sense...
[innerPool drain];
}
나는 그 항목이 폴더 인 경우 해당 폴더 등 다시 자신을 호출,
startingPath
의 각 항목에서 외모와 재귀 함수를 작성하는 경우 모델을 구축하는 방법을 볼 수 있습니다
에. 하지만 NSDirectoryEnumerator
으로 모델을 만들려면 어떻게해야합니까? 아마 그게 수업이 존재하는 이유 일거야, 그렇지?