iOS- NSFilemanger 文件管理對(duì)象常用方法

1.單例對(duì)象:在程序運(yùn)行期間,只有一個(gè)對(duì)象存在
NSFileManger *manger = [NSFileManger defaultManger];

2.判斷某個(gè)路勁文件是否存在
Bool isExist = [manger fileExistsAtPath:filePath];

3.判斷是否是一個(gè)目錄
Bool isDir;
 [manger fileExistsAtPath:filePath  diDirectory:&isDir];

4.判斷文件是否可讀
Bool isRead = [manger isReadableFileAtPath:filePath];

5.判斷文件是否可寫(xiě)
Bool isWrite = [manger isWriteableFileAtPath:filePath];

6.判斷文件是否可以刪除
Bool isDel = [manger isDeletableFileAtPath:filePath];

用法:
7.獲取文件的屬性(信息)
NSDictionary *dict = [fm attributesOfItemAtPath:filePath error:nil];

8.使用遞歸方式獲取文件及子目錄
NSArray *subPaths = [fm subpathsAtPath:dirPath];

9.直接獲取文件及子目錄
subPaths = [fm subpathsOfDirectoryAtPath:dirPath error:nil];

10. 獲取指定目錄下的文件及目錄信息(不在獲取后代路徑)
subPaths = [fm contentsOfDirectoryAtPath:dirPath error:nil];
fi

11. 根據(jù)路徑創(chuàng)建文件
BOOL isYES = [fm createDirectoryAtPath:createDirPath withIntermediateDirectories:YES attributes:nil error:nil];

12.將字符串轉(zhuǎn)換成二進(jìn)制數(shù)據(jù)
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];

13.移動(dòng)文件
[fm moveItemAtPath:createDirPath toPath:targetPath error:nil];

14.刪除文件
[fm removeItemAtPath:targetPath error:nil];
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容