Deprecated NSFileManager Methods
A method identified as deprecated has been superseded and may become unsupported in the future.
Deprecated in iOS 2.0
changeFileAttributes:atPath:
Changes the attributes of a given file or directory. (Deprecated in iOS 2.0. Use setAttributes:ofItemAtPath:error: instead.)
Parameters
- attributes
A dictionary containing as keys the attributes to set for path and as values the corresponding value for the attribute. You can set following:
NSFileBusy,NSFileCreationDate,NSFileExtensionHidden,NSFileGroupOwnerAccountID,NSFileGroupOwnerAccountName,NSFileHFSCreatorCode,NSFileHFSTypeCode,NSFileImmutable,NSFileModificationDate,NSFileOwnerAccountID,NSFileOwnerAccountName,NSFilePosixPermissions. You can change single attributes or any combination of attributes; you need not specify keys for all attributes.For the
NSFilePosixPermissionsvalue, specify a file mode from the OR’d permission bit masks defined insys/stat.h. See the man page for thechmodfunction (man 2 chmod) for an explanation.- path
A path to a file or directory.
Return Value
YES if all changes succeed. If any change fails, returns NO, but it is undefined whether any changes actually occurred.
Discussion
As in the POSIX standard, the app either must 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.
The NSFilePosixPermissions value must be initialized with the code representing the POSIX file-permissions bit pattern. NSFileHFSCreatorCode and NSFileHFSTypeCode will only be heeded when path specifies a file.
Special Considerations
Because this method does not return error information, it has been deprecated as of OS X v10.5. Use setAttributes:ofItemAtPath:error: instead.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
Declared In
NSFileManager.hcreateDirectoryAtPath:attributes:
Creates a directory (without contents) at a given path with given attributes. (Deprecated in iOS 2.0. Use createDirectoryAtURL:withIntermediateDirectories:attributes:error: instead.)
Parameters
- path
The path at which to create the new directory. The directory to be created must not yet exist, but its parent directory must exist.
- attributes
The file attributes for the new directory. The attributes you can set are owner and group numbers, file permissions, and modification date. If you specify
nilfor attributes, default values for these attributes are set (particularly write access for the creator and read access for others). The “Constants” section lists the global constants used as keys in the attributes dictionary. Some of the keys, such asNSFileHFSCreatorCodeandNSFileHFSTypeCode, do not apply to directories.
Return Value
YES if the operation was successful, otherwise NO.
Special Considerations
Because this method does not return error information, it has been deprecated as of OS X v10.5. Use createDirectoryAtPath:withIntermediateDirectories:attributes:error: instead.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
See Also
Declared In
NSFileManager.hcreateSymbolicLinkAtPath:pathContent:
Creates a symbolic link identified by a given path that refers to a given location. (Deprecated in iOS 2.0. Use createSymbolicLinkAtURL:withDestinationURL:error: instead.)
Parameters
- path
The path for a symbolic link.
- otherPath
The path to which path should refer.
Return Value
YES if the operation is successful, otherwise NO. Returns NO if a file, directory, or symbolic link identical to path already exists.
Discussion
Creates a symbolic link identified by path that refers to the location otherPath in the file system.
Special Considerations
Because this method does not return error information, it has been deprecated as of OS X v10.5. Use createSymbolicLinkAtPath:withDestinationPath:error: instead.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
See Also
Declared In
NSFileManager.hdirectoryContentsAtPath:
Returns the directories and files (including symbolic links) contained in a given directory. (Deprecated in iOS 2.0. Use contentsOfDirectoryAtPath:error: instead.)
Parameters
- path
A path to a directory.
Return Value
An array of NSString objects identifying the directories and files (including symbolic links) contained in path. Returns an empty array if the directory exists but has no contents. Returns nil if the directory specified at path does not exist or there is some other error accessing it.
Discussion
The search is shallow, and therefore does not return the contents of any subdirectories and does not traverse symbolic links in the specified directory. This returned array does not contain strings for the current directory (“.”), parent directory (“..”), or resource forks (begin with “._”).
Special Considerations
Because this method does not return error information, it has been deprecated as of OS X v10.5. Use contentsOfDirectoryAtPath:error: instead.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
See Also
Declared In
NSFileManager.hfileAttributesAtPath:traverseLink:
Returns a dictionary that describes the POSIX attributes of the file specified at a given. (Deprecated in iOS 2.0. Use attributesOfItemAtPath:error: instead.)
Parameters
- path
A file path.
- flag
If path is not a symbolic link, this parameter has no effect. If path is a symbolic link, then:
If
YESthe attributes of the linked-to file are returned, or if the link points to a nonexistent file the method returnsnil.If
NO, the attributes of the symbolic link are returned.
Return Value
An NSDictionary object that describes the POSIX attributes of the file specified at path. The keys in the dictionary are described in “File Attribute Keys”. If there is no item at path, returns nil.
Discussion
This code example gets several attributes of a file and logs them.
NSFileManager *fileManager = [[NSFileManager alloc] init]; |
NSString *path = @"/tmp/List"; |
NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:path traverseLink:YES]; |
if (fileAttributes != nil) { |
NSNumber *fileSize; |
NSString *fileOwner; |
NSDate *fileModDate; |
if (fileSize = [fileAttributes objectForKey:NSFileSize]) { |
NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]); |
} |
if (fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName]) { |
NSLog(@"Owner: %@\n", fileOwner); |
} |
if (fileModDate = [fileAttributes objectForKey:NSFileModificationDate]) { |
NSLog(@"Modification date: %@\n", fileModDate); |
} |
} |
else { |
NSLog(@"Path (%@) is invalid.", path); |
} |
[fileManager release]; |
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 dictionary: fileGroupOwnerAccountName, fileModificationDate, fileOwnerAccountName, filePosixPermissions, fileSize, fileSystemFileNumber, fileSystemNumber, and fileType. For example, you could rewrite the file modification statement in the code example above as:
if (fileModDate = [fileAttributes fileModificationDate]) |
NSLog(@"Modification date: %@\n", fileModDate); |
Special Considerations
Because this method does not return error information, it has been deprecated as of OS X v10.5. Use attributesOfItemAtPath:error: instead.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
Declared In
NSFileManager.hfileSystemAttributesAtPath:
Returns a dictionary that describes the attributes of the mounted file system on which a given path resides. (Deprecated in iOS 2.0. Use attributesOfFileSystemForPath:error: instead.)
Parameters
- path
Any pathname within the mounted file system.
Return Value
An NSDictionary object that describes the attributes of the mounted file system on which path resides. See “File-System Attribute Keys” for a description of the keys available in the dictionary.
Special Considerations
Because this method does not return error information, it has been deprecated as of OS X v10.5. Use attributesOfFileSystemForPath:error: instead.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
See Also
Declared In
NSFileManager.hpathContentOfSymbolicLinkAtPath:
Returns the path of the directory or file that a symbolic link at a given path refers to. (Deprecated in iOS 2.0. Use destinationOfSymbolicLinkAtPath:error: instead.)
Parameters
- path
The path of a symbolic link.
Return Value
The path of the directory or file to which the symbolic link path refers, or nil upon failure. If the symbolic link is specified as a relative path, that relative path is returned.
Special Considerations
Because this method does not return error information, it has been deprecated as of OS X v10.5. Use destinationOfSymbolicLinkAtPath:error: instead.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
See Also
Declared In
NSFileManager.hfileManager:shouldProceedAfterError:
An NSFileManager object sends this message to its handler for each error it encounters when copying, moving, removing, or linking files or directories. (Deprecated in iOS 2.0. See delegate methods for copy, move, remove, and link methods.)
Parameters
- manager
The file manager that sent this message.
- errorInfo
A dictionary that contains two or three pieces of information (all
NSStringobjects) 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 Value
YES if the operation (which is often continuous within a loop) should proceed, otherwise NO.
Discussion
An NSFileManager object, manager, sends this message for each error it encounters when copying, moving, removing, or linking files or directories. The return 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 alert dialog and leaves it to the user whether to proceed or stop:
-(BOOL)fileManager:(NSFileManager *)manager |
shouldProceedAfterError:(NSDictionary *)errorInfo |
{ |
int result; |
result = NSRunAlertPanel(@"Gumby App", @"File operation error: |
%@ with file: %@", @"Proceed", @"Stop", NULL, |
[errorInfo objectForKey:@"Error"], |
[errorInfo objectForKey:@"Path"]); |
if (result == NSAlertDefaultReturn) |
return YES; |
else |
return NO; |
} |
Special Considerations
The copyPath:toPath:handler:, movePath:toPath:handler:, removeFileAtPath:handler:, and linkPath:toPath:handler: methods have all been deprecated as of OS X v10.5. Instead, you can call the setDelegate: method to specify a delegate that can receive a variety of messages, including messages that replace those described in this section. See the descriptions of the delegate methods in this document for details.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
Declared In
NSFileManager.hfileManager:willProcessPath:
An NSFileManager object sends this message to a handler immediately before attempting to move, copy, rename, or delete, or before attempting to link to a given path. (Deprecated in iOS 2.0. See delegate methods for copy, move, link, and remove methods.)
Parameters
- manager
The
NSFileManagerobject that sent this message.- path
The path or a file or directory that manager is about to attempt to move, copy, rename, delete, or link to.
Discussion
You can implement this method in your handler to monitor file operations.
Special Considerations
The copyPath:toPath:handler:, movePath:toPath:handler:, removeFileAtPath:handler:, and linkPath:toPath:handler: methods have all been deprecated as of OS X v10.5. Instead, you can call the setDelegate: method to specify a delegate that can receive a variety of messages, including messages that replace those described in this section. See the descriptions of the delegate methods in this document for details.
Availability
- Available in iOS 2.0 and later.
- Deprecated in iOS 2.0.
Declared In
NSFileManager.h© 2013 Apple Inc. All Rights Reserved. (Last updated: 2013-03-14)