Par*_*att 2 iphone ios4 nsdocumentdirectory
我试过用
NSString *DocumentsDirectoryPath = //Code to fetch the Documents Directory Path;
NSError *error;
NSFileManager *manager = [NSFileManager defaultManager];
[manager removeItemAtPath:DocumentsDirectoryPath error:&error];
Run Code Online (Sandbox Code Playgroud)
上面的代码删除了我的应用程序的整个Documents目录,但我只想删除Documents目录的内容而不是 Documents目录本身.
我该怎么办?
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSFileManager *localFileManager=[[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:docsDir];
NSString *file;
NSError *error;
while ((file = [dirEnum nextObject]))
{
NSString *fullPath = [NSString stringWithFormat:@"%@/%@", docsDir,file];
// process the document
[localFileManager removeItemAtPath: fullPath error:&error ];
}
[localFileManager release];
Run Code Online (Sandbox Code Playgroud)
请参阅此链接以获得答案:
如何删除Documents目录的内容(而不是Documents目录本身)?
希望这能帮助所有寻求解决方案的人:)
| 归档时间: |
|
| 查看次数: |
2455 次 |
| 最近记录: |