通过终端,您可以使用命令 - “SetFile -a B 文件名”
以编程方式,我认为我应该通过 [[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:NO attributes:attributes error:nil];
但我找不到哪个。
谢谢
最佳答案
能够以编程方式设置捆绑位仍然很有用,例如 iPhoto 这样做是为了使 iPhoto Library 文件夹显示为单个文件。
您可以使用 Carbon 文件管理器 API 以编程方式设置捆绑位。您需要确保您的应用链接到 Carbon 框架并导入 <Carbon/Carbon.h>
header 。这些调用是 64 位安全的。
- (void)setBundleBitOfFile:(NSString*)path toBool:(BOOL)newValue
{
const char* pathFSR = [path fileSystemRepresentation];
FSRef ref;
OSStatus err = FSPathMakeRef((const UInt8*)pathFSR, &ref, /*isDirectory*/ NULL);
if (err == noErr)
{
struct FSCatalogInfo catInfo;
union FinderInfoTransmuter finderInfoPointers = { .bytes = catInfo.finderInfo };
err = FSGetCatalogInfo(&ref,
kFSCatInfoFinderInfo,
&catInfo,
/*outName*/ NULL,
/*FSSpec*/ NULL,
/*parentRef*/ NULL);
if (err == noErr)
{
if (newValue)
finderInfoPointers.finderInfo->finderFlags |= kHasBundle;
else
finderInfoPointers.finderInfo->finderFlags &= ~kHasBundle;
FSSetCatalogInfo(&ref,
kFSCatInfoFinderInfo,
&catInfo);
}
}
}
- (BOOL)bundleBitOfFile:(NSString*)path
{
BOOL value = NO;
const char* pathFSR = [path fileSystemRepresentation];
FSRef ref;
OSStatus err = FSPathMakeRef((const UInt8*)pathFSR, &ref, /*isDirectory*/ NULL);
if (err == noErr)
{
struct FSCatalogInfo catInfo;
union FinderInfoTransmuter finderInfoPointers = { .bytes = catInfo.finderInfo };
err = FSGetCatalogInfo(&ref,
kFSCatInfoFinderInfo,
&catInfo,
/*outName*/ NULL,
/*FSSpec*/ NULL,
/*parentRef*/ NULL);
if (err == noErr)
{
value = (BOOL)(((finderInfoPointers.finderInfo->finderFlags) & kHasBundle) == kHasBundle);
}
}
return value;
}
关于objective-c - 以编程方式制作 mac 包/包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2009687/