我正在研究一种方法,用于识别用户mac上的其他装入磁盘的kindle。 如果kindle无法通过名称识别,我的应用程序将通过查找包含文件类型的磁盘(例如.prc,.azw,.mobi,.mbp等)来决定安装哪个磁盘。等等)。这里是代码:objectForKey:NSFileType返回NULL
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++工作了很长一段时间,但我是相当新的目标C和可可,所以任何帮助将是非常感激的,我道歉提前如果这是一个noob问题。
想通了。我没有将/ Volumes/DISKNAME添加到attributesOfPath –
看起来像'enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:'('NSFileManager')的作业 – nielsbot