Changing file permissions

Discussion in 'Mac Programming' started by cea, Nov 11, 2009.

  1. cea macrumors newbie

    Oct 26, 2009
    I just did a test to change file permissions. It works but it does not pop up the Authentication dialog.
    Is there something wrong?
    Thank you:

    #import "untitled.h"

    @implementation untitled
    - (IBAction)myAction:(id)sender
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *path = @"/Users/cea/Desktop/";
    // Set permissions to prohibit access from other users
    NSDictionary *attr=[NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedLong:0777UforKey:NSFilePosixPermissions];
    fileManager setAttributes:attr ofItemAtPath:path error:nil];
    NSLog(@"0777 %@"path);

  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    First, if you own a file or folder, then you always have the ability to change its permissions. No authentication dialog is needed.

    Second, changing the permissions to 0777 (octal) does not prohibit access by others. Quite the opposite: it grants read and write access to everyone. Anyone can read or write to the file. It also marks the file as executable, which is simply wrong for a zip file.

    Why do you think 0777 will prohibit access from others? Please give the full name or URL of the reference or book you're reading this from.
  3. cea thread starter macrumors newbie

    Oct 26, 2009
    ohh the comment belongs to another test code which was here before. i just forgot to remove it.
    Thank you for your info!

Share This Page