回答
您可以設置隱形屬性通過一些C調用。這是相當原始的代碼,只適用於某些文件系統,並且缺少錯誤檢查。
#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <sys/attr.h>
#include <sys/errno.h>
#include <unistd.h>
#include <sys/vnode.h>
typedef struct attrlist attrlist_t;
struct FInfoAttrBuf {
u_int32_t length;
fsobj_type_t objType;
union {
char rawBytes[32];
struct {
FileInfo info;
ExtendedFileInfo extInfo;
} file;
struct {
FolderInfo info;
ExtendedFolderInfo extInfo;
} folder;
} finderInfo;
};
typedef struct FInfoAttrBuf FInfoAttrBuf;
static int SetFileInvisibility(const char *path, int isInvisible) {
attrlist_t attrList;
FInfoAttrBuf attrBuf;
memset(&attrList, 0, sizeof(attrList));
attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
int err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
if (err != 0)
return errno;
// attrBuf.objType = (VREG | VDIR), inconsequential for invisibility
UInt16 flags = CFSwapInt16BigToHost(attrBuf.finderInfo.file.info.finderFlags);
if (isInvisible)
flags |= kIsInvisible;
else
flags &= (~kIsInvisible);
attrBuf.finderInfo.file.info.finderFlags = CFSwapInt16HostToBig(flags);
attrList.commonattr = ATTR_CMN_FNDRINFO;
err = setattrlist(path, &attrList, attrBuf.finderInfo.rawBytes, sizeof(attrBuf.finderInfo.rawBytes), 0);
return err;
}
或者你可以通過NSURL
如果你可以針對雪豹它抽象掉了每個文件系統進程和處理擴展屬性。
NSURL *url = [NSURL fileURLWithPath:path];
[url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsHiddenKey error:NULL];
(編輯:前面的點似乎並沒有保持它mdfind的)「」
文件與開始將默認隱藏在Finder中。用戶可以用defaults
鍵覆蓋該鍵,但這通常會處理它。
聚光燈,見TA24975,其中詳細解釋了什麼Lyndsey提到。您可能需要結合這些方法,具體取決於您是否試圖避免mdfind -name
撿起它。
謝謝,我想知道是否有任何搜索API可以使用設置隱藏標誌。我正在搜索如何使用Finder API的標誌kIsInvisible,以及如何使用設置particulatr文件的不可見標誌。 – AmitSri 2010-06-03 08:20:41
AmitSri:它是文件目錄信息的一部分。使用'FSGetCatalogInfo'來獲取文件的Finder'FileInfo'結構(在目錄中,信息結構作爲字節數組,出於某種原因宣佈),設置隱形位和清除inited位,然後用'FSSetCatalogInfo'以應用更改。 – 2010-06-04 07:09:48
- 1. 如何使用gdata-objectivec-client?
- 2. 使用AFNetworking 3.X ObjectiveC
- 3. 使用gdata-objectivec-client授權
- 4. 如何獲得/提交使用 「谷歌API-的ObjectiveC客戶」
- 5. 如何在ObjectiveC中使用變量的值?
- 6. 的ObjectiveC - 如何使用NSUserNotification標識屬性
- 7. Circle使用不同的按鈕ObjectiveC
- 8. ObjectiveC中的CGContextFillPath如何工作?
- 9. 如何使用uisearchcontroller在ios 9中添加tableview的搜索選項,使用objectiveC
- 10. 如何在objectiveC類中使用struct和union?
- 11. 如何在ObjectiveC項目中使用C++文件
- 12. 如何使用Objectivec文件和Swift文件創建框架
- 13. 如何在ObjectiveC中聲明和使用3維數組?
- 14. ObjectiveC中的MulticastDelegate
- 15. 中的ObjectiveC
- 16. 在的ObjectiveC
- 17. 在的ObjectiveC
- 18. 在的ObjectiveC
- 19. 在的ObjectiveC
- 20. Shape文件用的ObjectiveC
- 21. NumberFormatter - ObjectiveC
- 22. 問題在使用ObjectiveC++編譯器
- 23. ObjectiveC如何實現class_createInstance(Class cls,size_t extraBytes)?
- 24. ObjectiveC mutableCopy如何快速運行
- 25. 如何將double轉換爲HH:MM:SS ObjectiveC
- 26. 如何動畫浮動UIView在ObjectiveC
- 27. ObjectiveC - 如何訪問OS X服務「Summarize」
- 28. 突破在的ObjectiveC
- 29. 從objectiveC調用javascript函數
- 30. 從ObjectiveC類中引用UIViewController
感謝您的代碼,我會盡可能在我的應用中實現代碼。因爲我需要照顧應用程序中的任何種類的不兼容。 – AmitSri 2010-06-15 07:58:59