ios 删除文件

- (void)removeFileWithName:(NSString *)fileName
{
    // you need to write a function to get to that directory
    NSString *filePath = [[self stringForDocumentDirectroy]stringByAppendingPathComponent:fileName];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:filePath])
    {
        NSError *error;
        if (![fileManager removeItemAtPath:filePath error:&error])
        {
            NSLog(@"Error removing file: %@", error);
        }
        else
        {
            NSLog(@"successed removed file");
        }
    }
}

 其中 [self stringForDocumentDirectroy]是document目录,

猜你喜欢

转载自zhong871004.iteye.com/blog/1679832