如何在 macOS 中搜索任何卷?

山姆
 - (void)readFolder:(NSString *)str :(NSMutableDictionary *)dict {
    NSArray *appFolderContents = [[NSArray alloc] init];
    appFolderContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:str error:nil];
    for (NSString *app in appFolderContents) {
        if ([app containsString:@".app"])
        {
            NSString *appName = [[app lastPathComponent] stringByDeletingPathExtension];
            NSString *appPath = [NSString stringWithFormat:@"%@/%@", str, app];
            NSString *appBundle = [[NSBundle bundleWithPath:appPath] bundleIdentifier];
//            NSLog(@"%@ -- %@", appPath, appBundle);
            NSArray *jumboTron = [NSArray arrayWithObjects:appName, appPath, appBundle, nil];
            [dict setObject:jumboTron forKey:appName];
        }
    }
}

//This searches for apps
- (void)getAPPList {
    NSMutableDictionary *myDict = [[NSMutableDictionary alloc] init];

    [self readFolder:@"/Applications" :myDict];
    [self readFolder:@"/Applications/Utilities" :myDict];
    [self readFolder:@"/System/Library/CoreServices" :myDict];
    [self readFolder:@"/Volumes/Macintosh HD/Applications" :myDict ];

// Volumes not named 'Macintosh HD' doesn't work, I'm trying to make it work
    [self readFolder:@"/Volumes/*/Applications" :myDict ];
//Some apps are stored in the user's Application folder instead of the main one
    [self readFolder:[NSString stringWithFormat:@"%@/Applications", NSHomeDirectory()] :myDict];
//Sometimes people keep apps in Downloads
    [self readFolder:[NSString stringWithFormat:@"%@/Downloads", NSHomeDirectory()] :myDict];
//Some apps are stored in the user's Library/Application Support sometimes
    [self readFolder:[NSString stringWithFormat:@"%@/Library/Application Support", NSHomeDirectory()] :myDict];

我试图让第 26 ( [self readFolder:@"/Volumes/*/Applications" :myDict ]) 行搜索所有卷,而不是仅搜索具有匹配/特定名称的卷。我怎样才能做到这一点?

我正在使用 Xcode 9.2

基思·诺伯

这样的事情应该可以解决问题(未经测试)

   NSArray *keys = [NSArray arrayWithObjects:NSURLVolumeURLKey, NSURLIsVolumeKey, nil];
   NSArray *volumeUrls = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:keys options:NSVolumeEnumerationSkipHiddenVolumes];
  for (NSURL *volumeUrl in volumeUrls)
  {
     BOOL mayBeBootVolume = NO;
     NSString* pathToVolume = [volumeUrl path];
     [self readFolder: [pathToVolume stringByAppendingString: @"/Applications"];
  }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章