iOS 檔案以及資料夾相關操作

2021-06-19 14:03:40 字數 1622 閱讀 6178

檔案相關操作

/*** 返回解壓成功或失敗.需要使用到ziparchive

* srcfile:待解壓檔案全路徑 destfile:解壓檔案全路徑.

**/+(bool)unzipfile:(nsstring*)srcfile tofile:(nsstring *)destfile withdeleteflag:(bool) bdel

[ziprelease];

if (bdel)

return bunzip;

}/**

* 判斷資料夾是否存在,不存在則建立對應資料夾.

* strdir:資料夾全路徑.

**/+(void)ifnotcreatedir:(nsstring*)strdir

nslog(@"%@",strdir);}}

/***  

刪除檔案.

* strdir:檔案全路徑.

**/+(void)deletefile:(nsstring*)strdir

else }

/***  複製檔案.

* srcfile:原檔案全路徑.destfile:目標檔案全路徑

**/+(bool)copyfile:(nsstring *)srcfile tofile:(nsstring *)destfile

else }

/*** 判斷檔案是否存在,不存在則建立.

* strfile:檔案全路徑.

**/+(bool)createfileifnotexist:(nsstring *)strfile

return true; }

/***

讀取文字檔案的每行,寫入nsarray.

* strfile:檔案全路徑.

**/+(nsarray*)readtxtlines:(nsstring *)strfile

/*** 

讀取文字檔案的每行中制定字元類間的資料.

* strfile:檔案全路徑.strpreflag:前分割字元,如「<";strbackflag:前分割字元,如「>";

**/+(nsarray*)readtxtlines:(nsstring *)strfile withpreflag:(nsstring *)strpreflag andbackflag:(nsstring *)strbackflag}}

return arr;

}/**

* 判斷檔案是否可讀.

* strfile:檔案全路徑;

**/+(bool)isfilecanread:(nsstring *)strfile

/*** 

判斷檔案是否可寫.

* strfile:檔案全路徑;

**/+(bool)isfilecanwrite:(nsstring *)strfile

/*** 判斷檔案是否相同.

* **/

+(bool)isfile:(nsstring *)strsrcfile equaltofile:(nsstring *)strdestfile

/***

修改檔名.

* **/

+(bool)renamefile:(nsstring *)stroldfile tofile:(nsstring *)strnewfile

檔案 資料夾的相關操作

有些時候,需要對檔案進行重新命名 刪除等一些操作,python的os模組中都有這麼功能 os模組中的rename 可以完成對檔案的重新命名操作 rename 需要修改的檔名,新的檔名 import os os.rename 畢業 txt 畢業 最終版.txt os模組中的remove 可以完成對檔案...

Windows,Linux資料夾相關操作

參考 判斷資料夾是否存在 在windows環境下標頭檔案為 include在linux環境下標頭檔案為 include下述函式在windows和linux環境下均可使用 int access const char filename,int accessmode 該函式功能為確定檔案或資料夾的訪問許可...

C 操作檔案以及資料夾

class program fs.write info,0,info.length fs.close catch exception ee copy檔案 支援copy後重新命名 public static void copyfile if file.exists objectpath 目標檔案 fi...