我有这个密码,没事的。
NSString *pathName = [@"/Users/" stringByAppendingString:NSUserName()];
pathName = [pathName stringByAppendingString:@"/Library/Application Support/AddressBook/Configuration.plist"];
[[NSFileManager defaultManager] removeItemAtPath:pathName error:nil];我想使用这个目录,但是有一个带有cbk4yc7r.default.的文件夹每个用户的cbk4yc7r更改。如何修改代码以使用此目录?
"/Library/Application Support/Firefox/Profiles/cbk4yc7r.default/places.sqlite"我尝试了"/Library/Application Support/Firefox/Profiles/*.default/places.sqlite“”,但在objective中不起作用。
你能帮帮我吗?谢谢
发布于 2012-02-29 10:09:27
假设您知道每个用户的cbk4yc7r是什么,您可以这样做:
[NSString stringWithFormat:@"/Library/Application Support/Firefox/Profiles/%@.default/places.sqlite", user.dirString];其中,user.dirstring相当于每个用户的cbk4yc7r。
发布于 2012-02-29 10:18:23
首先,你应该使用
NSString *pathName = [@"~/Library/Application Support/Firefox/Profiles/" stringByExpandingTildeInPath];为了获得正确的父目录,第二,该目录中的概要文件由~/Library/Application Support/Firefox/profiles.ini文件定义。"Path=Profiles/cbk4yc7r.default“,因此您需要解析profiles.ini或使用
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathName error:&error];发布于 2012-02-29 10:29:49
最好的解决方案是使用一些Firefox (如果存在)来确定配置文件ID。但我不太了解Firefox的内部结构,不知道这是否可行。不过,我知道单个用户可以拥有多个配置文件,这是需要考虑的问题。
而且,您(坦率地说,还有其他响应者)对目录结构做了很多假设,但这些假设并不一定会保持不变。您还假设一切都正常工作,当然,对于磁盘操作来说,这是不一定的。考虑到这些考虑因素,我提交了以下内容,其中相当彻底地使用了Foundation提供的抽象。它还酌情使用更现代的NSURL:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *appDirErr;
NSURL *appSupportDir = [fileManager URLForDirectory:NSApplicationSupportDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:NO
error:&appDirErr];
if (appSupportDir) {
NSURL *firefoxDir = [appSupportDir URLByAppendingPathComponent:@"Firefox/Profiles"
isDirectory:YES];
NSError *profileErr;
NSArray *profileURLs = [fileManager contentsOfDirectoryAtURL:firefoxDir
includingPropertiesForKeys:nil
options:0
error:&profileErr];
if (profileURLs) {
for (NSURL *currentProfileURL in profileURLs) {
NSURL *removalURL = [currentProfileURL URLByAppendingPathComponent:@"places.sqlite"
isDirectory:NO];
NSError *removalErr;
if (! [fileManager removeItemAtURL:removalURL error:&removalErr]) {
NSLog(@"Error! %@", [removalErr localizedDescription]);
}
}
}
else {
NSLog(@"Error! %@", [profileErr localizedDescription]);
}
}
else {
NSLog(@"Error! %@", [appDirErr localizedDescription]);
}https://stackoverflow.com/questions/9496984
复制相似问题