首页 > 解决方案 > 如何使用目标 c 获取文件的“Stationary Pad”标志信息

问题描述

我需要检查文件的“Stationary Pad”标志,但我没有任何方法可以读取此信息。

标签: objective-ccocoa

解决方案


你必须使用 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文字处理器的开源版本。


推荐阅读