Objective c 从文件列表中标识目录

Objective c 从文件列表中标识目录,objective-c,ios,cocoa-touch,Objective C,Ios,Cocoa Touch,我可以在一个路径上获取文件列表,但无法从列表中删除所有目录 fileList = [[myFileManager contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/%@",documentsDir, appDelegate.user_name] error:&theError] retain]; NSLog(@"FileList: %@", fileList); for (int i =0; i<

我可以在一个路径上获取文件列表,但无法从列表中删除所有目录

    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--;
    }
}
fileList=[[myFileManager内容目录路径:[NSString]
stringWithFormat:@“%@/%@”,documentsDir,appDelegate。用户名]错误:&错误]
保留];
NSLog(@“文件列表:%@”,文件列表);
对于(int i=0;i<[文件列表计数];i++)
{
NSString*fileName=[fileList objectAtIndex:i];
如果([fileName hasSuffix:@“dir”])
{
NSLog(@“dir found”);
[文件列表移除对象索引:i];
我--;
}
}
我显然误解了如何执行此操作,有人能建议我如何执行此操作吗

for (NSString *path in fileList) {

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

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

参数
路径文件或目录的路径。如果路径以波浪号(~)开头,则必须首先使用stringByExpandingTildeInPath展开路径,或 此方法将返回NO

isDirectory返回时,如果path是目录,或者如果最终path元素是指向目录的符号链接,则包含YES, 否则包含NO。如果路径不存在,则返回值为 未定义。如果不需要此信息,请传递NULL

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