In my cache directory i have a folder name Example. In that Example folder I am having sub folders CSS
, JS
. Now I want to remove the CSS
subfolder. I am not getting
I used the below written code. If I use this my entire Example folder is getting removed.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *cacheFolderPath = [NSSearchPathForDirectoriesInDomains(NSCacheDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSError *error = nil;
for (NSString *fileName in [fileManager contentsOfDirectoryAtPath:cacheFolderPath error:&error])
{
[fileManager removeItemAtPath:[cacheFolderPath stringByAppendingPathComponent:fileName] error:&error];
}
can any one help me.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *cacheFolderPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSError *error = nil;
NSString *dir = [cacheFolderPath stringByAppendingPathComponent:@"yourCSSSUBFolderName"];
[[NSFileManager defaultManager] removeItemAtPath:dir error:nil];
You can do the same for any other directories you want to delete!
Later if you want to add those files than first create that subfolder and than add your files for e-g:
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES);
NSString *directory = [paths objectAtIndex:0];
NSString *dirPath=[directory stringByAppendingPathComponent:@"yourCSSSUBFolderName"];
NSFileManager *fileManger=[NSFileManager defaultManager];
if(![fileManger fileExistsAtPath:dirPath])
{
NSError *error = nil;
[fileManger createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:&error];
}
// now add the directories
NSString *filePath = [dirPath stringByAppendingPathComponent:@"Yourfile.extension"];
[yourData writeToFile:filePath atomically:YES]; //Write to file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With