2012-02-04 3 views
0

파일 목록에서 디렉토리를 식별,하지만 난 누군가가 조언 해 줄 수 있습니다, 내가 분명히이 실행하는 방법에 대해 오해하고있어 목록내가 경로에 파일의 목록을 얻을 수

fileList = [[myFileManager contentsOfDirectoryAtPath:[NSString 
stringWithFormat:@"%@/%@",documentsDir, appDelegate.user_name] error:&theError] 
retain]; 



NSLog(@"FileList: %@", fileList); 

for (int i =0; i< [fileList count]; i++) 
{ 
    NSString *fileName = [fileList objectAtIndex:i]; 

    if ([fileName hasSuffix:@"dir"]) 
    { 
     NSLog(@"dir found"); 
     [fileList removeObjectAtIndex:i]; 
     i--; 
    } 
} 

에서 모든 디렉토리를 제거 할 수 없습니다 나 한테 어떻게? doc에서

답변

0
for (NSString *path in fileList) { 

    BOOL isDir = NO; 
    if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir]) { 

    if(isDir){ 
     //... 
    } 
    } 
} 

:

- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory 

매개 변수
경로 파일이나 디렉토리의 경로. 경로가 물결표 (~)로 시작되면 먼저 stringByExpandingTildeInPath 또는 으로 확장해야합니다.이 메서드는 NO를 반환합니다. 경로는 디렉토리 또는 최종 경로 요소는 디렉토리를 가리키는 기호 링크 인 경우 달리 NO를 포함하는 경우 돌아온

isDirectory은 YES 포함한다. path가 없으면 반환 값은 입니다. 이 정보가 필요하지 않으면 NULL을 전달하십시오.

관련 문제