gpt4 book ai didi

objective-c - objectForKey :NSFileType returns NULL

转载 作者:行者123 更新时间:2023-12-03 18:00:47 24 4
gpt4 key购买 nike

我正在研究一种方法,可以从用户 mac 上其他已安装的磁盘中识别出 kindle。如果无法通过名称识别 kindle,我的应用程序将通过查找包含 kindle 使用的文件类型(例如 .prc、.azw、.mobi、.mbp 等)的磁盘来确定哪个安装的磁盘是 kindle )。这是代码:

    NSLog(@"Scanning every file");
NSMutableArray *mountedDisks = [[NSMutableArray alloc] init];
mountedDisks = [workspace mountedRemovableMedia];

NSMutableArray *subpaths = [[NSMutableArray alloc] init];

int currentSubpath;
int proprietaryFilesFound;

while ([mountedDisks count] > currentDisk && [mountedDisks count] != 0)
{
subpaths = [manager subpathsAtPath:[mountedDisks objectAtIndex:currentDisk]];
currentSubpath = 0;
proprietaryFilesFound = 0;
NSLog(@"Entered outer loop");

while ([subpaths count] > currentSubpath && [subpaths count] != 0 && [[[manager attributesOfFileSystemForPath:[mountedDisks objectAtIndex:currentDisk] error:NULL] objectForKey:NSFileSystemSize] longLongValue] / 1073741824 <= 5 && proprietaryFilesFound < 7)
{
NSLog(@"Scanning %@, filetype is %@", [subpaths objectAtIndex:currentSubpath], [[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:NULL] objectForKey:NSFileType]);
if ([[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:NULL] objectForKey:NSFileType] isEqual: @"azw"] || [[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:NULL] objectForKey:NSFileType] isEqual: @"mbp"] || [[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:NULL] objectForKey:NSFileType] isEqual: @"prc"] || [[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:NULL] objectForKey:NSFileType] isEqual: @"mobi"])
{
proprietaryFilesFound++;
NSLog(@"Proprietary file found");
}
currentSubpath++;
}
currentDisk++;
}

不幸的是,当我运行以下代码行时,返回 NULL。

[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:NULL] objectForKey:NSFileType]

我已经使用 C++ 很长时间了,但我对 Objective C 和 cocoa 还很陌生,所以任何帮助将不胜感激,如果这是一个菜鸟问题,我提前道歉。

最佳答案

不要将 NULL 传递给错误参数,而是将指针传递给 NSError 并查看返回的错误。例如:

NSError *error;
[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:&error] objectForKey:NSFileType];
NSLog(@"%@", error);

关于objective-c - objectForKey :NSFileType returns NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6700006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com