读取里面的〜/ Library / Preferences /

时间:2015-06-22 17:06:42

标签: objective-c xcode macos

我试图访问〜/ Library / Preferences /,但我的代码无效。

NSString *resPath = @"~/Library/Preferences/";

    NSError *error = nil;

    NSArray *filenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:&error];

    if (!error)

    {

        for (NSString * filename in filenames)

        {

                NSLog(@"%@", filename);

        }
    }

也许我应该请求一些许可..任何想法?

1 个答案:

答案 0 :(得分:2)

您需要使用NSString方法:stringByExpandingTildeInPath~扩展为完整路径。

NSString *resPath = [@"~/Library/Preferences/" stringByExpandingTildeInPath];
NSLog(@"resPath: %@", resPath);

输出:

  

resPath:/ Volumes / User / me / Library / Preferences