回答
您可以设置隐形属性通过一些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. 使用AFNetworking 3.X ObjectiveC
- 2. 如何在objectiveC类中使用struct和union?
- 3. 如何使用Objectivec文件和Swift文件创建框架
- 4. 如何在ObjectiveC项目中使用C++文件
- 5. 中的ObjectiveC
- 6. 在的ObjectiveC
- 7. 在的ObjectiveC
- 8. 在的ObjectiveC
- 9. Shape文件用的ObjectiveC
- 10. NumberFormatter - ObjectiveC
- 11. 如何动画浮动UIView在ObjectiveC
- 12. 如何将double转换为HH:MM:SS ObjectiveC
- 13. ObjectiveC如何实现class_createInstance(Class cls,size_t extraBytes)?
- 14. 从ObjectiveC类中引用UIViewController
- 15. 从Objectivec中调用C main
- 16. 从objectiveC调用javascript函数
- 17. JSON ObjectiveC - 错误
- 18. 的ObjectiveC,创建类的
- 19. 的ObjectiveC:使用的NSString和__weak当奇怪的行为与ARC
- 20. 排序具有的ObjectiveC
- 21. Python的AppKit和ObjectiveC代表
- 22. ObjectiveC中的静态变量
- 23. 什么是ObjectiveC中的retainCount?
- 24. MVC中的ObjectiveC编程
- 25. 的ObjectiveC AVAudioPlayer量为0
- 26. ObjectiveC分配和init?
- 27. ObjectiveC随机数字
- 28. 如何在ObjectiveC中使用解析版本1.12.0在PFQueryTableViewController中加载对象?
- 29. 如何检查数组的内容?解析XML文件的ObjectiveC
- 30. 如何解决下面代码中的泄漏?的ObjectiveC
感谢您的代码,我会尽可能在我的应用中实现代码。因为我需要照顾应用程序中的任何种类的不兼容。 – AmitSri 2010-06-15 07:58:59