ios - 区分目录和文件

标签 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

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

最佳答案

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

关于ios - 区分目录和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16421648/

相关文章:

android - 无法获取 UICollectionView 中单击的单元格的 Firebase 数据库 key

ios - 使用适用于 iOS 的 FlickrKit 进行身份验证

Objective-C 复制 View

ios - NSString 二进制操作

ios - 无法为 AVCaptureVideoPreviewLayer 设置边界

ios - 在 Realm 中存储值

iphone - 关闭 iPhone 屏幕

python - ImportError : attempted relative import with no known parent package :(

perl - 如何使用 Perl 在 Windows 上创建 Unicode 目录?

ruby - 在整个目录上执行 Ruby 脚本