【问题标题】:Getting the "locked" state of a file on macOS在 macOS 上获取文件的“锁定”状态
【发布时间】:2019-09-21 10:13:10
【问题描述】:

可以通过 Finder 的“获取信息”窗口锁定文件以防删除。

我需要在我的程序中确定此锁定状态。我需要一个现代(精通 64 位)C/ObjC/Swift API 操作来让我做到这一点。

【问题讨论】:

标签: macos nsurl nsfilemanager


【解决方案1】:

这是NSURLIsUserImmutableKey 资源键。偷偷摸摸,因为文档没有提到“锁定”。

因此,要获取锁定状态,请使用以下代码:

- (BOOL)isLocked {
    NSNumber *result;
    if ([self.url getResourceValue:&result forKey:NSURLIsUserImmutableKey error:nil]) {
        return result.boolValue;
    }
    return NO;
}

【讨论】:

    猜你喜欢
    • 2021-02-17
    • 2021-10-30
    • 1970-01-01
    • 2016-06-15
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    相关资源
    最近更新 更多