Tôi tìm thấy mã bên dưới để xóa tệp trong mục tiêu-c, nhưng tôi muốn chỉ xóa tất cả các tệp trong thư mục Caches
và giữ thư mục Caches
chinh no.Mục tiêu c: Làm thế nào để chỉ xóa tất cả tập tin trong một thư mục nhưng giữ cho chính thư mục
Ai đó có thể đề xuất phương pháp để làm điều đó?
Cảm ơn
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
if ([filemgr removeItemAtPath: [NSHomeDirectory() stringByAppendingString:@"/Library/Caches"] error: NULL] == YES)
NSLog (@"Remove successful");
else
NSLog (@"Remove failed");
CẬP NHẬT
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];
Làm thế nào về tái tạo thư mục Caches sau khi xóa? – ohho
Bạn có thể xóa thư mục và sau đó tạo lại thư mục, mặc dù bạn phải đảm bảo rằng bạn duy trì quyền chính xác. – dreamlax
Ý tưởng hay, cảm ơn –