objective-c - 如何使用目标 c 获取文件的“Stationary Pad”标志信息
问题描述
我需要检查文件的“Stationary Pad”标志,但我没有任何方法可以读取此信息。
解决方案
你必须使用 Carbon File Manager API 来做到这一点,你不能在 Cocoa 中做到这一点。也就是说,这段代码在 Xcode 12 beta 中仍然有效。
-(BOOL)isStationaryPad:(NSString *)path
{
static kIsStationary = 0x0800;
CFURLRef url;
FSRef fsRef;
FSCatalogInfo catInfo;
BOOL success;
url = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)path, kCFURLPOSIXPathStyle, FALSE);
if (!url) return NO;
success = CFURLGetFSRef(url, &fsRef);
CFRelease(url);
// catalog info from file system reference; isStationary status from catalog info
if (success && (FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catInfo, nil, nil, nil))==noErr)
{
return ((((FileInfo*)catInfo.finderInfo)->finderFlags & kIsStationary) == kIsStationary);
}
return NO;
}
此代码来自Bean文字处理器的开源版本。
推荐阅读
- oauth - 让 Apigee 为客户端做身份验证(oauth)
- javascript - 如何在 JS 中返回两个连续异步函数的值?
- ios - 如何对 String 和 NSAttributedString 使用泛型类型?
- sql-server - 索引扫描而不是索引查找
- google-bigquery - 在 Bigquery 中使用 SQL 创建表备份
- exe - 将 nodejs excel 插件部署为 pkg/exe
- php - 如何在 Lumen 中获取验证错误消息?
- python - 从 Python 中的排序交易列表计算余额
- go - 我如何阅读这个 YAML?
- vert.x - 如何在 vert.x 选择查询上设置行数限制