You can set the invisibility attribute through some C calls. This is pretty crude code that only works on some file systems and lacks error checking.
#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; }
or you can go through NSURL if you can target Snow Leopard, which abstracts how each file system handles and handles extended attributes.
NSURL *url = [NSURL fileURLWithPath:path]; [url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsHiddenKey error:NULL];
Ashley clark
source share