ios/cocoa 删除文件

来源:互联网 发布:socket() 函数源码 编辑:程序博客网 时间:2024/06/08 13:56

贴出一个删除本地xml文件的函数,文件名为:”.weatherxml“

函数首先获取程序的home路径,再获取文件全路径,之后调用NSFileManager:removeItemAtPath方法删除指定文件

-(void)delWeatherXml

{

    NSString * HomeDirectory;

    NSString * theFilePath;

    NSArray * arry=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

    if([arry count])

    {

        HomeDirectory= [[NSString alloc] initWithFormat:[arry objectAtIndex:0]];

NSLog(HomeDirectory);

    }

    theFilePath = [HomeDirectory stringByAppendingPathComponent:@".weatherxml"]; 

    NSLog(theFilePath);

    NSFileManager *defaultManager; 

    defaultManager = [NSFileManager defaultManager];

    

    BOOL boolValue=[defaultManager removeItemAtPath: theFilePath error: nil];

    

    if (boolValue) 

    {

        NSLog(@"remove weatherxml file ok");

    }     

}

原创粉丝点击