I am working on a method that identifies a kindle out of other mounted disks on the users mac. If the kindle can't be identified by name, my app will decide which mounted disk is a kindle by going through and finding a disk containing file types the kindle uses (ex. .prc, .azw, .mobi, .mbp, etc). Here is the code:
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(@"Proprieta开发者_Python百科ry file found");
}
currentSubpath++;
}
currentDisk++;
}
Unfortunately, when I run the following line of code, NULL is returned.
[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:NULL] objectForKey:NSFileType]
I have worked with C++ for a long time, but I am fairly new to objective c and cocoa, so any help would be greatly appreciate, and I apologize ahead of time if this is a noob question.
Instead of passing NULL
to the error parameter, pass a pointer to an NSError
and see what error you get back. For example:
NSError *error;
[[manager attributesOfItemAtPath:[subpaths objectAtIndex:currentSubpath] error:&error] objectForKey:NSFileType];
NSLog(@"%@", error);
i suggest to check your "currentSubpath" variable, when manipulating path strings, it's easy to forgot a (holy) slash ...
精彩评论