What's the equivalent of C's:
chmod(MY_FILE, 0777);
in Objective C? I am trying to write to an existing locked file without performing
chmod +x MY_FILE
on the terminal.
To change the file permissions using chmod, run chmod <permission> <directory or filename> , swapping in the desired file permissions and the directory or file. The owner can change file permissions for any user, group or others by adding - to remove or + to add certain permissions.
The chmod (short for change mode) command is used to manage file system access permissions on Unix and Unix-like systems. There are three basic file system permissions, or modes, to files and directories: read (r) write (w) execute (x)
You can use Cocoa's -setAttributes:ofItemAtPath:error:
to do this job.
[[NSFileManager defaultManager] setAttributes:@{ NSFilePosixPermissions : @0666 }
ofItemAtPath:…
error:&error];
Of course you need the rights to do that.
You can use C's chmod()
.
Enter man 2 chmod
in the terminal for the documentation and related functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With