OC 檔案系統操作

2021-07-02 05:50:36 字數 1792 閱讀 6229

1.檔案的路徑查詢

nslog(@"nstemporarydirectory=%@", nstemporarydirectory());

//系統中用來建立臨時檔案的目錄路徑名

nslog(@"nshomedirectory=%@",nshomedirectory());

//返回當前使用者的主目錄

nslog(@"nshomedirectoryforuser=%@",nshomedirectoryforuser(@"ryt"));

//返回使用者user的主目錄

nslog(@"nsusername=%@",nsusername());

//返回當前使用者的登入名

nslog(@"nsfullusername=%@",nsfullusername());

//返回當前使用者的完整使用者名稱

2.路徑相關方法

//從路徑中提取最後乙個檔名

nsstring * str = [nshomedirectory() lastpathcomponent];

nslog(@"str=%@",str);

//將檔名附加到路徑末尾

nslog(@"addname=%@",addname);

//返回字尾

nsstring *returnsafix=[addname pathextension];

nslog(@"returnsafix=%@",returnsafix);

//返回路徑包含檔名的陣列

nsarray * filenames = [nshomedirectory() pathcomponents];

nslog(@"filenames=%@",filenames);

nsstring * removesymbol=[addname stringbystandardizingpath];

nslog(@"removesymbol=%@",removesymbol);

3.nsfilemanager

//建立檔案管理物件

nsfilemanager * fm = [nsfilemanager defaultmanager];

bool i***ists = [fm fileexistsatpath:nshomedirectory()];

nslog(@"%d",i***ists);

//建立檔案

nsstring * path = nshomedirectory();

nsstring * string = @"haha test";

nsdata * data = [string datausingencoding:nsutf8stringencoding];

bool createfile = [fm createfileatpath:path contents:data attributes:nil];

nslog(@"%d",createfile);

//拷貝檔案

nsstring * otherpath = nstemporarydirectory();

bool iscopy =[fm copyitematpath:path topath:otherpath error:nil];

nslog(@"%d",iscopy);

//刪除檔案

bool isremove = [fm removeitematpath:path error:nil];

nslog(@"%d",isremove);

檔案系統操作

1 分割槽硬碟 fdisk dev sdb n 建立分割槽,邏輯分割槽和主分割槽 主分割槽範圍1 4 邏輯分割槽5,6.2 格式化檔案分割槽 mkfs.type 分割槽 3 將分割槽掛載目錄 mount 分割槽 目錄 被掛載的目錄原始內容不可訪問 4 檔案許可權 umask 0022 預設許可權66...

作業系統 檔案系統

5.2開啟檔案 在作業系統中就是確定程序操作哪個檔案。這個確定過程由兩個事件構成 1.將使用者程序task struct中的 filp 20 與核心中的file table 64 進行掛接。2.將使用者程序需要開啟的檔案對應的i節點在file table 64 中進行登記。filp 20 掌控乙個程...

作業系統 檔案系統

通過設計乙個基於索引結構的檔案系統,了解檔案系統設計以及物理塊分配的基本概念。硬體環境 計算機一台,區域網環境 軟體環境 windows 作業系統 visual studio2019 1 設計乙個檔案系統的索引結構,描述邏輯結構與物理索引結構之間的關係 2 檔案建立等基本功能 段 問1 這個標頭檔案...