分享

OC学习之文件目录操作

 叹落花 2015-01-11

#import <Foundation/Foundation.h>


int main(int argc, const char * argv[])

{


    @autoreleasepool {

        

        // insert code here...

        //NSLog(@"Hello, World!");

        NSFileManager *fm;

        NSString      *path;

        NSString      *dirName = @"testdir";


        fm   = [NSFileManager defaultManager];

        path = [fm currentDirectoryPath];

        NSLog(@"The Current path is : %@", path);

        //创建目录

        if( [fm createDirectoryAtPath:dirName withIntermediateDirectories:YES attributes:nil error:NULL] == NO)

        {

            NSLog(@"Can't Create directory !");

            return  1;

        }

        else

        {

             NSLog(@"Create directory successfull!");

        }

        //重命名目录

        if( [fm moveItemAtPath:dirName toPath:@"newtestdir" error:NULL]== NO)

        {

            NSLog(@"Can't edit directory !");

            return  2;

        }

        else

        {

            NSLog(@" Create directory successfull!");

           

        }

        //更改目录为当前目录

        if( [fm changeCurrentDirectoryPath:@"newtestdir"] == NO )

        {

            NSLog(@"Can't change directory !");

            return  2;

        }

        else

        {

            NSLog(@"Change directory successfull!");

           

        }

        //获取并显示当前的工作目录

        path = [fm currentDirectoryPath];

        NSLog(@"Current directory is : %@",path);

        NSLog(@"All operations are successfull !");

    

        

    }

    return 0;

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多