区分目录和文件

时间:2013-05-07 14:30:05

标签: ios objective-c directory

我正在尝试确定数组是否包含具有以下代码的目录:

for (NSString *item in folderContents)
{
        NSString *itemPath = [subPath stringByAppendingPathComponent:item];

        BOOL isDirectory;
        if ([[NSFileManager defaultManager] fileExistsAtPath:subPath isDirectory:&isDirectory])
        {
                   if (isDirectory)
                   {                                
                       NSLog(@"sub-directory: %@", itemPath);
                   }
                   else
                   {
                       NSLog(@"document path: %@", itemPath);
                   }
         }
}

目前,该数组包含表示目录和.pdf文件的字符串,但两者都记录为目录:

sub-directory: /Users/.../Documents/downloads/Notices/folder/test document.pdf
sub-directory: /Users/.../Documents/downloads/Notices/folder/test folder

谁能告诉我我错过了什么?

1 个答案:

答案 0 :(得分:1)

您仍然测试子路径,而不是项目路径