objective-cのファイルを削除するには以下のコードがありますが、ディレクトリCaches
のすべてのファイルを削除し、自体。目的c:ディレクトリ下のすべてのファイルを削除しますが、ディレクトリ自体を保持する方法
誰かがその方法を提案できますか?
おかげ
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
if ([filemgr removeItemAtPath: [NSHomeDirectory() stringByAppendingString:@"/Library/Caches"] error: NULL] == YES)
NSLog (@"Remove successful");
else
NSLog (@"Remove failed");
は、そのディレクトリ内のファイルを介し
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
if ([filemgr removeItemAtPath: [NSHomeDirectory() stringByAppendingString:@"/Library/Caches"] error: NULL] == YES)
NSLog (@"Remove successful");
else
NSLog (@"Remove failed");
[filemgr createDirectoryAtPath: [NSHomeDirectory() stringByAppendingString:@"/Library/Caches"] withIntermediateDirectories:NO attributes:nil error:nil];
どのように削除した後にキャッシュフォルダを再作成しますでしょうか? – ohho
ディレクトリを削除してから再作成することもできますが、正しいアクセス許可を維持しておく必要があります。 – dreamlax
良いアイデア、ありがとう –