【问题标题】:Objective-C: Programmatically set file privileges to current userObjective-C:以编程方式为当前用户设置文件权限
【发布时间】:2011-08-09 19:53:42
【问题描述】:

我正在开发一个管理文档的程序。我的应用程序所做的其中一件事是从 Internet 下载文档并打开它们。我下载的这个文档需要以只读权限打开。

所以,我想知道是否有一种以编程方式设置文件权限的方法。

提前致谢。

【问题讨论】:

    标签: cocoa macos nsfilemanager


    【解决方案1】:

    除了@Vlad提到的chmod,还可以使用NSFileManagersetAttributes:ofItemAtPath:error:方法,属性为NSFileImmutable

    NSDictionary* attribs = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSFileImmutable];
    [[NSFileManager defaultManager]  setAttributes: attribs ofItemAtPath:@"/path/to/file" error:nil];
    

    【讨论】:

      【解决方案2】:

      当然,使用chmod

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-03
        • 2015-08-08
        相关资源
        最近更新 更多