PATH  Documentation > Mac OS X > Foundation Reference: Objective-C



Table of Contents

NSFileManager


Inherits from:
NSObject
Conforms to:
NSObject
(NSObject)
Declared in:
Foundation/NSFileManager.h




Class Description


NSFileManager enables you to perform many generic file-system operations. With it you can:

Besides offering a useful range of generic functionality, the NSFileManager API insulates an application from the underlying file system. An important part of this insulation is the encoding of file names (in, for example, Unicode, ISO Latin1, and ASCII). There is a default NSFileManager object for the file system; this object responds to all messages that request a operation on the associated file system.

The pathnames specified as arguments to NSFileManager methods can be absolute or relative to the current directory (which you can determine with currentDirectoryPath and set with changeCurrentDirectoryPath:). However, pathnames cannot include wildcard characters.


Note: An absolute pathname starts with the root directory of the file system, represented by a slash (/), and ends with the file or directory that the pathname identifies. A relative pathname is relative to the current directory, the directory in which you are working and in which saved files are currently stored (if no pathname is specified). Relative pathnames start with a subdirectory of the current directory-without an initial slash-and end with the name of the file or directory the pathname identifies.


Broken Links


Constructing a pathname to a file does not guarantee that the file exists at that path. Specifying a path results in one of the following possibilities:

If the pathname specifies a valid file or link, you can obtain information about the file using the methods of this class. If the pathname specifies a broken link, you can still use fileAttributesAtPath:traverseLink: to obtain attributes for the link itself (by specifying NO for the traverseLink argument). However, the methods fileExistsAtPath: and fileAttributesAtPath:traverseLink: (with YES specified for the traverseLink argument) return nil when the pathname specifies a broken link. Other methods return appropriate errors-see the method descriptions for specific information. Regardless of whether a link is broken or valid, the link still appears in directory listings.


Path Utilities


NSFileManager methods are commonly used together with path-utility methods implemented as a category on NSString. These methods extract the components of a path (directory, file name, and extension), create paths from those components, "translate" path separators, clean up paths containing symbolic links and redundant slashes, and perform similar tasks. Where your code manipulates strings that are part of file-system paths, it should use these methods. See the specification of the NSString class cluster for details.




Method Types


Getting the default manager
+ defaultManager
Directory operations
- changeCurrentDirectoryPath:
- createDirectoryAtPath:attributes:
- currentDirectoryPath
File operations
- copyPath:toPath:handler:
- createFileAtPath:contents:attributes:
- movePath:toPath:handler:
- linkPath:toPath:handler:
- removeFileAtPath:handler:
Getting and comparing file contents
- contentsAtPath:
- contentsEqualAtPath:andPath:
Determining access to files
- fileExistsAtPath:
- fileExistsAtPath:isDirectory:
- isReadableFileAtPath:
- isWritableFileAtPath:
- isExecutableFileAtPath:
- isDeletableFileAtPath:
Getting and setting attributes
- fileAttributesAtPath:traverseLink:
- fileSystemAttributesAtPath:
- changeFileAttributes:atPath:
Discovering directory contents
- directoryContentsAtPath:
- enumeratorAtPath:
- subpathsAtPath:
Symbolic-link operations
- createSymbolicLinkAtPath:pathContent:
- pathContentOfSymbolicLinkAtPath:
Converting file-system representations
- fileSystemRepresentationWithPath:
- stringWithFileSystemRepresentation:length:


Class Methods



defaultManager

+ (NSFileManager *)defaultManager

Returns the default NSFileManager object for the file system. You invoke all NSFileManager instance methods with this object as the receiver.


Instance Methods



changeCurrentDirectoryPath:

- (BOOL)changeCurrentDirectoryPath:(NSString *)path

Changes the path of the current directory to path and returns YES if successful, NO if not successful. All relative pathnames refer implicitly to the current working directory. The current working directory is stored per task.

See Also: - currentDirectoryPath, - fileExistsAtPath:isDirectory:, - directoryContentsAtPath:, - createDirectoryAtPath:attributes:



changeFileAttributes:atPath:

- (BOOL)changeFileAttributes:(NSDictionary *)attributes atPath:(NSString *)path

Changes the attributes of the file or directory specified by path. Attributes that you can change are the owner, group, file permissions, and modification date. As in the POSIX standard, the application must either own the file or directory or must be running as superuser for attribute changes to take effect. The method attempts to make all changes specified in attributes and ignores any rejection of an attempted modification. If all changes succeed, it returns YES. If any change fails, the method returns NO, but it is undefined whether any changes actually occurred.

Some useful global keys for identifying object values in the attributes dictionary are:


Key Value Type
NSFileModificationDate NSDate
NSFilePosixPermissions NSNumber

The NSFilePosixPermissions value must be initialized with the code representing the POSIX file-permissions bit pattern.

You can change single attributes or any combination of attributes; you need not specify keys for all four attributes.

See Also: - fileAttributesAtPath:traverseLink:



contentsAtPath:

- (NSData *)contentsAtPath:(NSString *)path

Returns the contents of the file specified in path as an NSData object. If path specifies a directory, or if some other error occurs, this method returns nil.

See Also: - contentsEqualAtPath:andPath:, - createFileAtPath:contents:attributes:



contentsEqualAtPath:andPath:

- (BOOL)contentsEqualAtPath:(NSString *)path1 andPath:(NSString *)path2

Compares the file or directory specified in path1 with that specified in path2 and returns YES if they have the same contents. If path1 and path2 are directories, the contents are the list of files and subdirectories each contain-contents of subdirectories are also compared. If the contents differ, this method returns NO. For files, this method checks to see if they're the same file, then compares their size, and finally compares their contents. It does not traverse symbolic links, but compares the links themselves.

See Also: - contentsAtPath:



copyPath:toPath:handler:

- (BOOL)copyPath:(NSString *)source toPath:(NSString *)destination handler:handler

Copies the directory or file specified in path source to a different location in the file system identified by path destination. If source is a file, the method creates a file at destination that holds the exact contents of the original file. If source is a directory, the method creates a new directory at destination and recursively populates it with duplicates of the files and directories contained in source, preserving all links. The file specified in source must exist, while destination must not exist prior to the operation. When a file is being copied, the destination path must end in a file name-there is no implicit adoption of the source file name. Symbolic links are not traversed but are themselves copied.

If the copy operation is successful, the method returns YES. If the operation is not successful, but the callback handler of fileManager:shouldProceedAfterError: returns YES (see below), copyPath:toPath:handler: also returns YES. Otherwise this copy method returns NO. The method also attempts to make the attributes of the directory or file at destination identical to source, but ignores any failure at this attempt.

handler identifies an object that responds to the callback messages fileManager:willProcessPath: and fileManager:shouldProceedAfterError: (see "Methods Implemented By the Delegate" , below). This callback mechanism is similar to delegation. NSFileManager sends the first message when it begins a copy, move, remove, or link operation. It sends the second message when it encounters any error in processing. You can specify nil for handler if no object responds to the callback messages. If you specify nil and an error occurs, the method automatically returns NO.

This code fragment verifies that the file to be copied exists and then copies that file to the user's ~/Library/Reports directory:

NSString *source = @"/tmp/quarterly_report.rtf";
NSString *destination = [[NSHomeDirectory()
        stringByAppendingPathComponent:@"Library"]
        stringByAppendingPathComponent:@"Reports"];
NSFileManager *manager = [NSFileManager defaultManager];

    if ([manager fileExistsAtPath:source])
    [manager copyPath:source toPath:destination handler:nil];

See Also: - linkPath:toPath:handler:, - movePath:toPath:handler:, - fileManager:shouldProceedAfterError:, - removeFileAtPath:handler:, - fileManager:willProcessPath:



createDirectoryAtPath:attributes:

- (BOOL)createDirectoryAtPath:(NSString *)path attributes:(NSDictionary *)attributes

Creates a directory (without contents) at path that has the specified attributes. Returns YES upon success or NO upon failure. The directory to be created must not yet exist, but its parent directory must exist. The file attributes you can set are owner and group numbers, file permissions, and modification date. If you specify nil for attributes, default values for these attributes are set (particularly write access for creator and read access for others). The following table lists the global constants used as keys in the attributes NSDictionary and the types of the associated values:
Key Value Type
NSFileModificationDate NSDate
NSFileOwnerAccountName NSString
NSFileGroupOwnerAccountName NSString
NSFilePosixPermissions NSNumber

See Also: - changeCurrentDirectoryPath:, - changeFileAttributes:atPath:, - createFileAtPath:contents:attributes:, - currentDirectoryPath



createFileAtPath:contents:attributes:

- (BOOL)createFileAtPath:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes

Creates a file at path that contains contents and has the specified attributes. Returns YES upon success or NO upon failure. The file attributes you can set are owner and group numbers, file permissions, and modification date. If you specify nil for attributes, the file is given a default set of attributes. The following table summarizes the keys and types to associate with values in the NSDictionary attributes.
Key Value Type
NSFileModificationDate NSDate
NSFileOwnerAccountName NSString
NSFileGroupOwnerAccountName NSString
NSFilePosixPermissions NSNumber

See Also: - contentsAtPath:, - changeFileAttributes:atPath:, - fileAttributesAtPath:traverseLink:



createSymbolicLinkAtPath:pathContent:

- (BOOL)createSymbolicLinkAtPath:(NSString *)path pathContent:(NSString *)otherPath

Creates a symbolic link identified by path that refers to the location otherPath in the file system. Returns YES if the operation is successful and NO if it is not successful. The method returns NO if a file, directory, or symbolic link identical to path already exists.

See Also: - pathContentOfSymbolicLinkAtPath:, - linkPath:toPath:handler:



currentDirectoryPath

- (NSString *)currentDirectoryPath

Returns the path of the program's current directory. The string returned by this method is initialized to the current working directory, and can thereafter be changed by invoking changeCurrentDirectoryPath:. If the program's current working directory isn't accessible, this method returns nil.

Relative pathnames refer implicitly to the current directory. For example, if the current directory is /tmp, and the relative pathname reports/info.txt is specified, the resulting full pathname is /tmp/reports/info.txt.

See Also: - createDirectoryAtPath:attributes:



directoryContentsAtPath:

- (NSArray *)directoryContentsAtPath:(NSString *)path

Searches the contents of the directory specified by path and returns an array of strings identifying the directories and files (including symbolic links) contained in path. The search is shallow and therefore does not return the contents of any subdirectories. This returned array does not contain strings for the current directory (".") or parent directory ("..") and does not traverse symbolic links. This method returns nil if the directory specified at path does not exist or there is some other error accessing it. It returns an empty array if the directory exists, but has no contents.

The following example, generated by NSArray's description method, shows the results when this method is invoked on the directory /System/Developer.

Source, 
Makefiles, 
ProjectTypes, 
Applications, 
Java, 
PBBundles, 
Apps, 
Demos, 
Headers, 
Examples

See Also: - currentDirectoryPath, - fileExistsAtPath:isDirectory:, - enumeratorAtPath:, - subpathsAtPath:



enumeratorAtPath:

- (NSDirectoryEnumerator *)enumeratorAtPath:(NSString *)path

Creates and returns an autoreleased NSDirectoryEnumerator object that enumerates the contents of the directory specified at path. Because the enumeration is deep-that is, it lists the contents of all subdirectories-this enumerator object is useful for preforming actions that involve large file-system subtrees. If the method is passed a directory on which another filesystem is mounted (a mount point), it traverses the mount point. If handed a symbolic link, it evaluates the link and returns an enumerator for the file or directory the link points to. If the link can not be evaluated, the method returns nil. If path is a filename, the method returns an enumerator object that enumerates no files-the first call to nextObject will return nil.

This code fragment enumerates the subdirectories and files under /MyAccount/Documents and processes all files with an extension of .doc:

NSString *file;
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]
        enumeratorAtPath:@"/MyAccount/Documents"];
while (file = [enumerator nextObject]) {
    if ([[file pathExtension] isEqualToString:@"doc"])
            [self scanDocument:file];
}

The NSDirectoryEnumerator class has methods for obtaining the attributes of the existing path and of the parent directory, and for skipping descendents of the existing path.

See Also: - currentDirectoryPath, - fileAttributesAtPath:traverseLink:, - directoryContentsAtPath:, - subpathsAtPath:



fileAttributesAtPath:traverseLink:

- (NSDictionary *)fileAttributesAtPath:(NSString *)path traverseLink:(BOOL)flag

Returns an NSDictionary containing various objects that represent the POSIX attributes of the file specified at path. You access these objects using the keys:
Key Value Type
NSFileSize (in bytes) NSNumber
NSFileModificationDate NSDate
NSFileOwnerAccountName NSString
NSFileGroupOwnerAccountName NSString
NSFileReferenceCount (number of hard links) NSNumber
NSFileIdentifier NSNumber
NSFileDeviceIdentifier NSNumber
NSFilePosixPermissions NSNumber
NSFileType NSString

The possible values for the NSFileType key are:

If flag is YES and path is a symbolic link, the attributes of the linked-to file are returned; if the link points to a non-existent file, this method returns nil. If flag is NO, the attributes of the symbolic link are returned.

This piece of code gets several attributes of a file and logs them.

NSNumber *fsize, *refs, *owner;
NSDate *moddate;

    NSDictionary *fattrs = [manager fileAttributesAtPath:@"/tmp/List" traverseLink:YES];

if (!fattrs) {
    NSLog(@"Path is incorrect!");
    return;
}

if (fsize = [fattrs objectForKey:NSFileSize])
    NSLog(@"File size: %d\n", [fsize intValue]);

if (refs = [fattrs objectForKey:NSFileReferenceCount])
    NSLog(@"Ref Count: %d\n", [refs intValue]);

if (moddate = [fattrs objectForKey:NSFileModificationDate])
    NSLog(@"Modif Date: %@\n", [moddate description]);

As a convenience, NSDictionary provides a set of methods (declared as a category in NSFileManager.h) for quickly and efficiently obtaining attribute information from the returned NSDictionary: fileGroupOwnerAccountName, fileModificationDate, fileOwnerAccountName, filePosixPermissions, fileSize, fileSystemFileNumber, fileSystemNumber, and fileType. For example, you could rewrite the last statement in the code example above as:

if (moddate = [fattrs fileModificationDate])
    NSLog(@"Modif Date: %@\n", [moddate description]);

See Also: - changeFileAttributes:atPath:



fileExistsAtPath:

- (BOOL)fileExistsAtPath:(NSString *)path

Returns YES if the file specified in path exists, or NO if it does not. If path specifies a symbolic link, this method traverses the link and returns YES or NO based on the existence of the file at the link destination.

See Also: - fileExistsAtPath:isDirectory:



fileExistsAtPath:isDirectory:

- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory

Returns whether the file specified in path exists. If you want to determine if path is a directory, specify the address of a boolean variable for isDirectory; the method indirectly returns YES if path is a directory. The method traverses final symbolic links.

This example gets an NSArray that identifies the fonts in /System/Library/Fonts:

NSArray *subpaths;
BOOL isDir;
NSString *fontPath = @"/System/Library/Fonts";
NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir)
    subpaths = [manager subpathsAtPath:fontPath];

See Also: - fileExistsAtPath:



fileSystemAttributesAtPath:

- (NSDictionary *)fileSystemAttributesAtPath:(NSString *)path

Returns an NSDictionary containing objects that represent attributes of the mounted file system; path is any pathname within the mounted file system. You access the attribute objects in the NSDictionary using these global constants as keys:
Key Value Type
NSFileSystemSize (in an appropriate unit, usually bytes) NSNumber
NSFileSystemFreeSize (in an appropriate unit, usually bytes) NSNumber
NSFileSystemNodes NSNumber
NSFileSystemFreeNodes NSNumber
NSFileSystemNumber NSNumber

The following code example checks to see if there's sufficient space on the file system before adding a new file to it:

const char *data = [[customerRec description] cString];
NSData *contents = [NSData dataWithBytes:data length:strlen(data)+1];
NSFileManager *manager = [NSFileManager defaultManager];
NSDictionary *fsattrs = 
        [manager fileSystemAttributesAtPath:@"/Net/sales/misc"];
if ([[fsattrs objectForKey:NSFileSystemFreeSize] unsignedIntValue] > 
        [contents length]) 
    [manager createFileAtPath:@"/Net/sales/misc/custrec.rtf"
            contents:contents attributes:nil];

See Also: - fileAttributesAtPath:traverseLink:, - changeFileAttributes:atPath:



fileSystemRepresentationWithPath:

- (const char *)fileSystemRepresentationWithPath:(NSString *)path

Returns a C-string representation of path that properly encodes Unicode strings for use by the file system. If you need the C string beyond the scope of your autorelease pool, you should copy it. This method raises an exception upon error. Use this method if your code calls system routines that expect C-string path arguments.

See Also: - stringWithFileSystemRepresentation:length:



isDeletableFileAtPath:

- (BOOL)isDeletableFileAtPath:(NSString *)path

Returns YES if the invoking object appears able to delete the directory or file specified in path and NO if it cannot. To be deletable, either the parent directory of path must be writable or its owner must be the same as the owner of the application process. If path is a directory, every item contained in path must be deletable. This method does not traverse symbolic links.

isExecutableFileAtPath:

- (BOOL)isExecutableFileAtPath:(NSString *)path

Returns YES if the underlying operating system appears able to execute the file specified in path and NO if it cannot. This method traverses symbolic links.

isReadableFileAtPath:

- (BOOL)isReadableFileAtPath:(NSString *)path

Returns YES if the invoking object appears able to read the file specified in path and NO if it cannot. This method traverses symbolic links.

isWritableFileAtPath:

- (BOOL)isWritableFileAtPath:(NSString *)path

Returns YES if the invoking object appears able to write to the file specified in path and NO if it cannot. This method traverses symbolic links.

linkPath:toPath:handler:

- (BOOL)linkPath:(NSString *)source toPath:(NSString *)destination handler:handler

If pathname source identifies a file, this method hard-links the file specified in destination to it. If destination is a directory, this method creates a file in destination with the same basename (final path element) as source, hard-linked to source.

If source is a directory or symbolic link, this method copies it to destination instead of creating a hard link. The file, link, or directory specified in source must exist, while destination must not yet exist. The destination path must end in a file name; there is no implicit adoption of the source file name. Symbolic links in source are not traversed.

If the link operation is successful, linkPath:toPath:handler: returns YES. If the operation is not successful, but the handler method fileManager:shouldProceedAfterError: returns YES, the method also returns YES. Otherwise it returns NO.

The argument handler identifies an object that responds to the callback messages fileManager:willProcessPath: and fileManager:shouldProceedAfterError: (see "Methods Implemented By the Delegate" , below). This callback mechanism is similar to delegation. NSFileManager sends the first message when it begins a copy, move, remove, or link operation. It sends the second message when it encounters any error in processing. You can specify nil for handler if no object responds to the callback messages; if you specify nil and an error occurs, the method automatically returns NO.

This code fragment verifies the pathname typed in a text field (imageFileField) and then links the file to the user's ~/Library/Images directory:

NSString *imageFile = [imageFileField stringValue];
NSString *destination = [[NSHomeDirectory()
    stringByAppendingPathComponent:@"Library"]
    stringByAppendingPathComponent:@"Images"];
NSFileManager *manager = [NSFileManager defaultManager];
	
if ([manager fileExistsAtPath:source])
    [manager linkPath:source toPath:destination handler:self];

See Also: - copyPath:toPath:handler:, - createSymbolicLinkAtPath:pathContent:, - movePath:toPath:handler:, - fileManager:shouldProceedAfterError:, - removeFileAtPath:handler:, - fileManager:willProcessPath:



movePath:toPath:handler:

- (BOOL)movePath:(NSString *)source toPath:(NSString *)destination handler:handler

Moves the directory or file specified in path source to a different location in the file system identified by the pathname destination. If source is a file, the method creates a file at destination that holds the exact contents of the original file and then deletes the original file. If source is a directory, movePath:toPath:handler: creates a new directory at destination and recursively populates it with duplicates of the files and directories contained in source. It then deletes the old directory and its contents. The file specified in source must exist, while destination must not yet exist. The destination path must end in a file name; there is no implicit adoption of the source file name. Symbolic links are not traversed; however, links are preserved.

If the move operation is successful, the method returns YES. If the operation is not successful, but the handler method fileManager:shouldProceedAfterError: returns YES, movePath:toPath:handler: also returns YES; otherwise it returns NO. If a failure in a move operation occurs, the pre-existing path or the new path remains intact, but not both.

The argument handler identifies an object that responds to the callback messages fileManager:willProcessPath: and fileManager:shouldProceedAfterError: (see "Methods Implemented By the Delegate" , below). This callback mechanism is similar to delegation. NSFileManager sends the first message when it begins a copy, move, remove, or link operation. It sends the second message when it encounters any error in processing. You can specify nil for handler if no object responds to the callback messages; if you specify nil and an error occurs, the method automatically returns NO.

See Also: - copyPath:toPath:handler:, - linkPath:toPath:handler:, - removeFileAtPath:handler:, - fileManager:shouldProceedAfterError:, - fileManager:willProcessPath:



pathContentOfSymbolicLinkAtPath:

- (NSString *)pathContentOfSymbolicLinkAtPath:(NSString *)cStringPath

Returns the actual path of the directory or file that the symbolic link cStringPath refers to. Returns nil upon failure.

See Also: - createSymbolicLinkAtPath:pathContent:



removeFileAtPath:handler:

- (BOOL)removeFileAtPath:(NSString *)path handler:handler

Deletes the file, link, or directory (including, recursively, all subdirectories, files and links in the directory) identified by path. If the removal operation is successful, removeFileAtPath:handler: returns YES. If the operation is not successful, but the handler method fileManager:shouldProceedAfterError: returns YES, removeFileAtPath:handler: also returns YES; otherwise it returns NO.

The argument handler identifies an object that responds to the callback messages fileManager:willProcessPath: and fileManager:shouldProceedAfterError: (see "Methods Implemented By the Delegate" , below). This callback mechanism is similar to delegation. NSFileManager sends the first message when it begins a copy, move, remove, or link operation. It sends the second message when it encounters any error in processing. You can specify nil for handler if no object responds to the callback messages; if you specify nil and an error occurs, the method automatically returns NO.

Since the removal of directory contents is so thorough and final, be careful when using this method. Do not specify "." or ".." for path; this raises the exception NSInvalidArgumentException. This method does not traverse symbolic links.

See Also: - copyPath:toPath:handler:, - linkPath:toPath:handler:, - movePath:toPath:handler:, - fileManager:shouldProceedAfterError:, - fileManager:willProcessPath:



stringWithFileSystemRepresentation:length:

- (NSString *)stringWithFileSystemRepresentation:(const char *)str length:(unsigned)len

Returns an NSString object converted from a C-string representation of a path name in the current file system (string). Use this method if your code receives paths as C-strings from system routines.

See Also: - fileSystemRepresentationWithPath:



subpathsAtPath:

- (NSArray *)subpathsAtPath:(NSString *)path

Returns an NSArray that lists (as NSStrings) the contents of the directory identified by path. This list of directory contents goes very deep and hence is very useful for large file-system subtrees. The method skips "." and "..". If path is a symbolic link, subpathsAtPath: traverses the link. The method returns nil if it cannot get the device of the linked-to file.

Here is a sample fragment of what subpathsAtPath: returns (as the output of NSArray's description method) when path is /System/Developer:

Examples/Foundation/ForwardInvocation/PB.project, 
Examples/Foundation/ForwardInvocation/Makefile,
Examples/Foundation/ForwardInvocation/TargetProxy.h, 
Examples/Foundation/ForwardInvocation/TargetProxy.m, 
Examples/Foundation/ForwardInvocation/ForwardInvocation_main.m, 
Examples/Foundation/MultiThreadedDO, 
Examples/Foundation/MultiThreadedDO/PB.project, 
Examples/Foundation/MultiThreadedDO/Makefile, 
Examples/Foundation/MultiThreadedDO/ThreadSafeQueue.h, 
Examples/Foundation/MultiThreadedDO/ThreadSafeQueue.m, 
Examples/Foundation/MultiThreadedDO/MultiThreadedDO_main.m, 

Notice that this method reveals every element of the subtree at path, including the contents of file packages (such as applications, nib files, and RTFD files). This code fragment gets the contents of /System/Library/Fonts after verifying that the directory exists:

BOOL isDir=NO;
NSArray *subpaths;
NSString *fontPath = @"/System/Library/Fonts";
NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir)
    subpaths = [manager subpathsAtPath:fontPath];

See Also: - directoryContentsAtPath:, - enumeratorAtPath:




Methods Implemented By the Delegate

The methods described in this section are methods to be implemented by the callback handler passed to several methods of NSFileManager.


fileManager:shouldProceedAfterError:

- (BOOL)fileManager:(NSFileManager *)manager shouldProceedAfterError:(NSDictionary *)errorInfo

NSFileManager sends this message for each error it encounters when copying, moving, removing, or linking files or directories. The NSDictionary object errorInfo contains two or three pieces of information (all NSStrings) related to the error:
Key Value
@"Path" The path related to the error (usually the source path)
@"Error" A description of the error
@"ToPath" The destination path (not all errors)

Return YES if the operation (which is often continuous within a loop) should proceed and NO if it should not; the Boolean value is passed back to the invoker of copyPath:toPath:handler:, movePath:toPath:handler:, removeFileAtPath:handler:, or linkPath:toPath:handler:. If an error occurs and your handler has not implemented this method, the invoking method automatically returns NO.

The following implementation of fileManager:shouldProceedAfterError: displays the error string in an attention panel and leaves it to the user whether to proceed or stop:

-(BOOL)fileManager:(NSFileManager *)manager 
        shouldProceedAfterError:(NSDictionary *)errorDict
{
    int result;
    result = NSRunAlertPanel(@"Gumby App", @"File operation error:
            %@ with file: %@", @"Proceed", @"Stop", NULL, 
            [errorDict objectForKey:@"Error"], 
            [errorDict objectForKey:@"Path"]);
	
    if (result == NSAlertDefaultReturn)
        return YES;
    else
        return NO;
}

See Also: - fileManager:willProcessPath:



fileManager:willProcessPath:

-(BOOL)fileManager:(NSFileManager *)manager willProcessPath:(NSString *)path

NSFileManager sends this message immediately before attempting to move, copy, or rename path or before attempting to link to path. You can implement this method in your delegate to monitor file operations. The return value is ignored.


Table of Contents