NSFileManager的應用,NSFileManager應用

來源:互聯網
上載者:User

NSFileManager的應用,NSFileManager應用
單例,是在 一個檔案中只建立一次就能夠全部一起共用,多建立的地址是相同的NSFileManager *manager=[NSFileManager defaultManager];是一個單例 NSFileManager *manager=[NSFileManager defaultManager];
        //判斷一個檔案或檔案夾是否存在
        //參數a表示參看檔案是不是目錄,如果是返回yes,如果是內容,則返回no
        //參數b表示檔案夾是否存在
        BOOL a;
        BOOL b= [manager fileExistsAtPath:@"/Users/zhangyunjiang/Desktop/視頻1/惡棍天使流暢.mp4" isDirectory:&a];        NSLog(@"%d %d",b,a);  //擷取檔案或檔案夾的屬性
        NSDictionary *dic= [manager attributesOfItemAtPath:@"/Users/zhangyunjiang/Desktop/視頻1/惡棍天使流暢.mp4" error:nil];        NSLog(@"%@",dic);  //擷取檔案中所有的檔案(弊端不能擷取檔案的檔案中裡面的資料)
       NSArray *arr=[manager contentsOfDirectoryAtPath:@"/Users/zhangyunjiang/Desktop/視頻1" error:nil];
        NSLog(@"%@",arr);
        //用subpathsAtPath可以擷取檔案的檔案裡面的資料
        NSArray *arr1=[manager subpathsAtPath:@"/Users/zhangyunjiang/Desktop/視頻1"];        NSLog(@"%@",arr1);  //拷貝       BOOL a=[manager copyItemAtPath:@"/Users/zhangyunjiang/Desktop/c語言/app c 練習/app" toPath:@"/Users/zhangyunjiang/Desktop/未命名檔案夾" error:nil];        NSLog(@"%d",a);//刪除        BOOL b=[manager removeItemAtPath:@"/Users/zhangyunjiang/Desktop/zyj" error:nil];        NSLog(@"%d",b);//移動(剪下)       BOOL c= [manager moveItemAtPath:@"/Users/zhangyunjiang/Desktop/未命名檔案夾/app" toPath:@"/Users/zhangyunjiang/Desktop/zyj" error:nil];        NSLog(@"%d",c); //建立檔案夾       BOOL a= [manager createDirectoryAtPath:@"/Users/zhangyunjiang/Desktop/zyj/jiuh/sdgre/fsdg" withIntermediateDirectories:YES attributes:nil error:nil];
        NSLog(@"%d",a);
       //建立檔案         BOOL b=[manager createFileAtPath:@"/Users/zhangyunjiang/Desktop/frty.txt" contents:nil attributes:nil];        NSLog(@"%d",b);

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.