我试图访问~/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);
}
}也许我应该请求一些许可..。有什么想法吗?
发布于 2015-06-22 17:22:39
您需要使用NSString方法:stringByExpandingTildeInPath将~扩展到完整路径。
NSString *resPath = [@"~/Library/Preferences/" stringByExpandingTildeInPath];
NSLog(@"resPath: %@", resPath);输出:
resPath: /卷/用户/me/库/首选项
https://stackoverflow.com/questions/30985837
复制相似问题