ios/cocoa 删除文件

来源:互联网 发布:家庭千兆网络布置 编辑:程序博客网 时间:2024/05/18 01:14

转自 http://blog.csdn.net/zhaozy55555/article/details/7671491

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

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

-(void)delWeatherXml

{

    NSString * HomeDirectory;

    NSString * theFilePath;

    NSArray * arry=NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

    if([arry count])

    {

        HomeDirectory= [[NSString allocinitWithFormat:[arry objectAtIndex:0]];

NSLog(HomeDirectory);

    }

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

    NSLog(theFilePath);

    NSFileManager *defaultManager; 

    defaultManager = [NSFileManager defaultManager];

    

    BOOL boolValue=[defaultManager removeItemAtPath: theFilePath errornil];

    

    if (boolValue) 

    {

        NSLog(@"remove weatherxml file ok");

    }     

}


原创粉丝点击