Monday, April 22, 2013

NSFileManager isWritableFileAtPath example ios

isWritableFileAtPath:

Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file.
- (BOOL)isWritableFileAtPath:(NSString *)path
Parameters
path
A file path.
Return Value
YES if the current process has write privileges for the file at path; otherwise NO if the process does not have write privileges or the existence of the file could not be determined.
Discussion of [NSFileManager isWritableFileAtPath]
If the file at path is inaccessible to your app, perhaps because it does not have search privileges for one or more parent directories, this method returns NO. This method traverses symbolic links in the path. This method also uses the real user ID and group ID, as opposed to the effective user and group IDs, to determine if the file is writable.
Example of [NSFileManager isWritableFileAtPath]
{

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?