2

使ってみた

NSString *DocumentsDirectoryPath = //Code to fetch the Documents Directory Path;
NSError *error;
NSFileManager *manager = [NSFileManager defaultManager];
[manager removeItemAtPath:DocumentsDirectoryPath error:&error];

上記のコードはアプリの Documents ディレクトリ全体を削除しますが、Documents ディレクトリ自体ではなくDocuments ディレクトリの内容を削除したいだけです。

私は何をすべきか?

4

1 に答える 1

6
 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];

答えについては、このリンクを参照してください。

Documents ディレクトリの内容 (Documents ディレクトリ自体ではなく) を削除するにはどうすればよいですか?

これが、これに対する解決策を探しているすべての人に役立つことを願っています:)

于 2011-03-31T12:36:54.457 に答える