开发者

Objective-C: Programmatically set file privileges to current user

开发者 https://www.devze.com 2023-03-27 10:46 出处:网络
I working on a program that mana开发者_运维技巧ges documents. One of the things my app does, is download document from the internet and open them. This documents I download need to be opened with Read

I working on a program that mana开发者_运维技巧ges documents. One of the things my app does, is download document from the internet and open them. This documents I download need to be opened with Read Only privileges.

So, I was wondering if there is a way of programmatically setting the privileges of a file.

Thanks in advance.


In addition to chmod mentioned by @Vlad, you can also use the setAttributes:ofItemAtPath:error: method of NSFileManager with an attribute of NSFileImmutable:

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


Sure, use chmod.

0

精彩评论

暂无评论...
验证码 换一张
取 消