views:

150

answers:

3

I want to use an open panel to let the user select a destination, but I want to alert them at that point that point that the directory is not-writable. I generally prefer to create it and handle the error, but that's not useful to me here, since I don't want to create the folder just yet. (I'll be sure to handle the error when I do create it, if there is one.)

I thought there might be a better way than to just create it and delete it, which would stink.

I tried doing this, thinking that "file" might mean file or directory like some other methods.

NSFileManager *fm = [NSFileManager defaultManager];
[fm isWritableFileAtPath:destinationString]

(I'm not sure yet if I want to offer the chance to authenticate to override permissions, but feel free to tell me how.)

+3  A: 

You want

-attributesOfItemAtPath:error:.

-jcr

NSResponder
Does that mean I have to look at filePosixPermissions, fileGroupOwnerAccountName, fileOwnerAccountName, NSUserName, and figure it out for myself?
zekel
+2  A: 

Yes, directories count as files.

Chuck
A: 

Weird. I tried isWriteableAtPath before and it didn't seem to work as I expected, but now with an isolated test does.

NSFileManager *fm = [NSFileManager defaultManager];
NSLog(@"%d /private/ writeable?", [fm isWritableFileAtPath:@"/private/"]);
NSLog(@"%d /Applications/ writeable?", [fm isWritableFileAtPath:@"/Applications/"]);
NSLog(@"%d /Users/MYUSERNAME/ writeable?", [fm isWritableFileAtPath:@"/Users/MYUSERNAME/"]);

Prints

0 /private/ writeable?
1 /Applications/ writeable?
1 /Users/MYUSERNAME/ writeable?
zekel