iOS下的檔案和資料夾的隱藏

2021-06-06 11:08:32 字數 998 閱讀 4019

在實際的開發過程中,有些情況下,需要將檔案或者資料夾隱藏起來,不讓使用者看到。

比如說在開啟documents的共享的時候,又不希望使用者通過itunes看到的情況下。

隱藏檔案,其實是利用unix檔案系統的特性,在檔案命名的時候加了乙個點「.」實現了隱藏檔案的效果。

例如:建立了乙個隱藏資料夾hidedir,之後在裡邊儲存了乙個檔案passwrod.txt

**如下:

nsstring* cachespath = [nssearchpathfordirectoriesindomains(nscachesdirectory,nsuserdomainmask,yes)objectatindex:0];

nsstring* hidedirpath = [nsstring stringwithformat:@"%@%@/", cachespath,@"/.hidedir"];

nsfilemanager* filemanager = [nsfilemanager defaultmanager];

bool isdir;

if (![filemanager fileexistsatpath:hidedirpath isdirectory:&isdir])

}nsstring* filepath = [nsstring stringwithformat:@"%@%@",hidedirpath, @"password.txt"];

nsdictionary * dic = [nsdictionary dictionarywithobject:@"pwd1"forkey:@"pwd"];

[dic writetofile:filepath atomically:yes];

//驗證一下,是否儲存成功

nsdictionary * context= [nsdictionary dictionarywithcontentsoffile:filepath];

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

隱藏檔案和資料夾的工具SecreteFolder

今天寫的乙個小工具,用來隱藏檔案和資料夾 2007 04 23 更新版本號為1.0,使用 主.年.月.日 格式 去掉了暫時沒有實現的 密碼 選項 功能 新增了 執行 功能,可以直接開啟沒有隱藏的檔案 資料夾 2007 04 18 新增 修改時選擇資料夾後自動加上 新增 修改時可以看見已隱藏的檔案和資...

檔案和資料夾的增刪

public class ccrdfile else else else 刪除單個檔案 param filepath return public static boolean deletefile string filepath return flag 刪除目錄 資料夾 以及目錄下的檔案 param...

檔案和資料夾的許可權

1 修改檔案的屬主和屬組chown option owner group file.用法 owner owner group group 命令中的冒號可用.替換 r 遞迴 chown option reference rfile file.範例 root vinnywang wang ll rw r...