Class: NSFileManager
Overview
The NSFileManager class enables you to perform many generic file-system operations and insulates an app from the underlying file system. Most file operations can be performed using the shared file manager object. In iOS and in OS X v10.5 and later, you can also create a unique instance of NSFileManager in cases where you want to use a delegate object in conjunction with the file manager.
Class Method Summary (collapse)
-
+ defaultManager
Returns the shared file manager object for the process.
Instance Method Summary (collapse)
-
- attributesOfFileSystemForPath:error:
Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.
-
- attributesOfItemAtPath:error:
Returns the attributes of the item at a given path.
-
- changeCurrentDirectoryPath:
Changes the path of the current working directory to the specified path.
-
- componentsToDisplayForPath:
Returns an array of strings representing the user-visible components of a given path.
-
- contentsAtPath:
Returns the contents of the file at the specified path.
-
- contentsEqualAtPath:andPath:
Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents.
-
- contentsOfDirectoryAtPath:error:
Performs a shallow search of the specified directory and returns the paths of any contained items.
-
- contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:
Performs a shallow search of the specified directory and returns URLs for the contained items.
-
- copyItemAtPath:toPath:error:
Copies the item at the specified path to a new location synchronously.
-
- copyItemAtURL:toURL:error:
Copies the file at the specified URL to a new location synchronously.
-
- createDirectoryAtPath:withIntermediateDirectories:attributes:error:
Creates a directory with given attributes at the specified path.
-
- createDirectoryAtURL:withIntermediateDirectories:attributes:error:
Creates a directory with the given attributes at the specified URL.
-
- createFileAtPath:contents:attributes:
Creates a file with the specified content and attributes at the given location.
-
- createSymbolicLinkAtPath:withDestinationPath:error:
Creates a symbolic link that points to the specified destination.
-
- createSymbolicLinkAtURL:withDestinationURL:error:
Creates a symbolic link at the specified URL that points to an item at the given URL.
-
- currentDirectoryPath
Returns the path of the program’s current directory.
-
- delegate
Returns the delegate for the receiver.
-
- destinationOfSymbolicLinkAtPath:error:
Returns the path of the item pointed to by a symbolic link.
-
- displayNameAtPath:
Returns the display name of the file or directory at a specified path.
-
- enumeratorAtPath:
Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path.
-
- enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:
Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified URL.
-
- evictUbiquitousItemAtURL:error:
Removes the local copy of the specified cloud-based item.
-
- fileExistsAtPath:
Returns a Boolean value that indicates whether a file or directory exists at a specified path.
-
- fileExistsAtPath:isDirectory:
Returns a Boolean value that indicates whether a file or directory exists at a specified path.
-
- fileSystemRepresentationWithPath:
Returns a C-string representation of a given path that properly encodes Unicode strings for use by the file system.
-
- init
Returns an initialized NSFileManager instance.
-
- isDeletableFileAtPath:
Returns a Boolean value that indicates whether the invoking object appears able to delete a specified file.
-
- isExecutableFileAtPath:
Returns a Boolean value that indicates whether the operating system appears able to execute a specified file.
-
- isReadableFileAtPath:
Returns a Boolean value that indicates whether the invoking object appears able to read a specified file.
-
- isUbiquitousItemAtURL:
Returns a Boolean indicating whether the item is targeted for storage in iCloud.
-
- isWritableFileAtPath:
Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file.
-
- linkItemAtPath:toPath:error:
Creates a hard link between the items at the specified paths.
-
- linkItemAtURL:toURL:error:
Creates a hard link between the items at the specified URLs.
-
- mountedVolumeURLsIncludingResourceValuesForKeys:options:
Returns an array of URLs that identify the mounted volumes available on the computer.
-
- moveItemAtPath:toPath:error:
Moves the file or directory at the specified path to a new location synchronously.
-
- moveItemAtURL:toURL:error:
Moves the file or directory at the specified URL to a new location synchronously.
-
- removeItemAtPath:error:
Removes the file or directory at the specified path.
-
- removeItemAtURL:error:
Removes the file or directory at the specified URL.
-
- replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:
Replaces the contents of the item at the specified URL in a manner that insures no data loss occurs.
-
- setAttributes:ofItemAtPath:error:
Sets the attributes of the specified file or directory.
-
- setDelegate:
Sets the delegate for the receiver.
-
- setUbiquitous:itemAtURL:destinationURL:error:
Sets whether the item at the specified URL should be stored in the cloud.
-
- startDownloadingUbiquitousItemAtURL:error:
Starts downloading (if necessary) the specified item to the local system.
-
- stringWithFileSystemRepresentation:length:
Returns an NSString object whose contents are derived from the specified C-string path.
-
- subpathsAtPath:
Returns an array of strings identifying the paths for all items in the specified directory.
-
- subpathsOfDirectoryAtPath:error:
Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories.
-
- ubiquityIdentityToken
Returns an opaque token that represents the current iCloud (“ubiquity”) identity.
-
- URLForDirectory:inDomain:appropriateForURL:create:error:
Locates and optionally creates the specified common directory in a domain.
-
- URLForPublishingUbiquitousItemAtURL:expirationDate:error:
Returns a URL that can be emailed to users to allow them to download a copy of a cloud-based item.
-
- URLForUbiquityContainerIdentifier:
Returns the URL for the ubiquity (iCloud) container associated with the specified container identifier, and establishes access to that container.
-
- URLsForDirectory:inDomains:
Returns an array of URLs for the specified common directory in the requested domains.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (NSFileManager) defaultManager
Returns the shared file manager object for the process. This method always returns the same file manager object. If you plan to use a delegate with the file manager to receive notifications about the completion of file-based operations, you should create a new instance of NSFileManager (using the init method) rather than using the shared object.
Instance Method Details
- (Hash) attributesOfFileSystemForPath(path, error:error)
Returns a dictionary that describes the attributes of the mounted file system on which a given path resides. This method does not traverse a terminal symbolic link.
- (Hash) attributesOfItemAtPath(path, error:error)
Returns the attributes of the item at a given path.
- (Boolean) changeCurrentDirectoryPath(path)
Changes the path of the current working directory to the specified path. All relative pathnames refer implicitly to the current working directory. Changing the current working directory affects only paths created in the current process.
- (Array) componentsToDisplayForPath(path)
Returns an array of strings representing the user-visible components of a given path. These components cannot be used for path operations and are only suitable for display to the user.
- (NSData) contentsAtPath(path)
Returns the contents of the file at the specified path.
- (Boolean) contentsEqualAtPath(path1, andPath:path2)
Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents. If path1 and path2 are directories, the contents are the list of files and subdirectories each contains—contents of subdirectories are also compared. For files, this method checks to see if they’re the same file, then compares their size, and finally compares their contents. This method does not traverse symbolic links, but compares the links themselves.
- (Array) contentsOfDirectoryAtPath(path, error:error)
Performs a shallow search of the specified directory and returns the paths of any contained items. This method performs a shallow search of the directory and therefore does not traverse symbolic links or return the contents of any subdirectories. This method also does not return URLs for the current directory (“.”), parent directory (“..”), or resource forks (files that begin with “._”) but it does return other hidden files (files that begin with a period character). If you need to perform a deep enumeration, use the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: method instead.The order of the files in the returned array is undefined.
- (Array) contentsOfDirectoryAtURL(url, includingPropertiesForKeys:keys, options:mask, error:error)
Performs a shallow search of the specified directory and returns URLs for the contained items. This method performs a shallow search of the directory and therefore does not traverse symbolic links or return the contents of any subdirectories. This method also does not return URLs for the current directory (“.”), parent directory (“..”), or resource forks (files that begin with “._”) but it does return other hidden files (files that begin with a period character). If you need to perform a deep enumeration, use the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: method instead.The order of the files in the returned array is undefined.
- (Boolean) copyItemAtPath(srcPath, toPath:dstPath, error:error)
Copies the item at the specified path to a new location synchronously. When copying items, the current process must have permission to read the file or directory at srcPath and write the parent directory of dstPath. If the item at srcPath is a directory, this method copies the directory and all of its contents, including any hidden files. If a file with the same name already exists at dstPath, this method aborts the copy attempt and returns an appropriate error. If the last component of srcPath is a symbolic link, only the link is copied to the new path.Prior to copying an item, the file manager asks its delegate if it should actually do so for each item. It does this by calling the fileManager:shouldCopyItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldCopyItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager copies the given file or directory. If there is an error copying an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:copyingItemAtURL:toURL: or fileManager:shouldProceedAfterError:copyingItemAtPath:toPath: method to determine how to proceed.
- (Boolean) copyItemAtURL(srcURL, toURL:dstURL, error:error)
Copies the file at the specified URL to a new location synchronously. When copying items, the current process must have permission to read the file or directory at srcURL and write the parent directory of dstURL. If the item at srcURL is a directory, this method copies the directory and all of its contents, including any hidden files. If a file with the same name already exists at dstURL, this method aborts the copy attempt and returns an appropriate error. If the last component of srcURL is a symbolic link, only the link is copied to the new path.Prior to copying each item, the file manager asks its delegate if it should actually do so. It does this by calling the fileManager:shouldCopyItemAtURL:toURL: method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the fileManager:shouldCopyItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager proceeds to copy the file or directory. If there is an error copying an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:copyingItemAtURL:toURL: or fileManager:shouldProceedAfterError:copyingItemAtPath:toPath: method to determine how to proceed.
- (Boolean) createDirectoryAtPath(path, withIntermediateDirectories:createIntermediates, attributes:attributes, error:error)
Creates a directory with given attributes at the specified path. If you specify nil for the attributes parameter, this method uses a default set of values for the owner, group, and permissions of any newly created directories in the path. Similarly, if you omit a specific attribute, the default value is used. The default values for newly created directories are as follows:Permissions are set according to the umask of the current process. For more information, see umask. The owner ID is set to the effective user ID of the process.The group ID is set to that of the parent directory.
- (Boolean) createDirectoryAtURL(url, withIntermediateDirectories:createIntermediates, attributes:attributes, error:error)
Creates a directory with the given attributes at the specified URL. If you specify nil for the attributes parameter, this method uses a default set of values for the owner, group, and permissions of any newly created directories in the path. Similarly, if you omit a specific attribute, the default value is used. The default values for newly created directories are as follows:Permissions are set according to the umask of the current process. For more information, see umask. The owner ID is set to the effective user ID of the process.The group ID is set to that of the parent directory.If you want to specify a relative path for url, you must set the current working directory before creating the corresponding NSURL object.
- (Boolean) createFileAtPath(path, contents:contents, attributes:attributes)
Creates a file with the specified content and attributes at the given location. If you specify nil for the attributes parameter, this method uses a default set of values for the owner, group, and permissions of any newly created directories in the path. Similarly, if you omit a specific attribute, the default value is used. The default values for newly created files are as follows:Permissions are set according to the umask of the current process. For more information, see umask. The owner ID is set to the effective user ID of the process.The group ID is set to that of the parent directory.If a file already exists at path, this method overwrites the contents of that file if the current process has the appropriate privileges to do so.
- (Boolean) createSymbolicLinkAtPath(path, withDestinationPath:destPath, error:error)
Creates a symbolic link that points to the specified destination. This method does not traverse symbolic links contained in either path or destPath.
- (Boolean) createSymbolicLinkAtURL(url, withDestinationURL:destURL, error:error)
Creates a symbolic link at the specified URL that points to an item at the given URL. This method does not traverse symbolic links contained in either url or destURL.
- (String) currentDirectoryPath
Returns the path of the program’s current directory. The string returned by this method is initialized to the current working directory; you can change the working directory by invoking changeCurrentDirectoryPath:. 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.
- (Object) delegate
Returns the delegate for the receiver.
- (String) destinationOfSymbolicLinkAtPath(path, error:error)
Returns the path of the item pointed to by a symbolic link.
- (String) displayNameAtPath(path)
Returns the display name of the file or directory at a specified path. Display names are user-friendly names for files. They are typically used to localize standard file and directory names according to the user’s language settings. They may also reflect other modifications, such as the removal of filename extensions. Such modifications are used only when displaying the file or directory to the user and do not reflect the actual path to the item in the file system. For example, if the current user’s preferred language is French, the following code fragment logs the name Bibliothèque and not the name Library, which is the actual name of the directory.
- (NSDirectoryEnumerator) enumeratorAtPath(path)
Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path. Because the enumeration is deep—that is, it lists the contents of all subdirectories—this enumerator object is useful for performing actions that involve large file-system subtrees. This method does not resolve symbolic links encountered in the traversal process, nor does it recurse through them if they point to a directory.This code fragment enumerates the subdirectories and files under a user’s Documents directory and processes all files with an extension of .doc: The NSDirectoryEnumerator class has methods for obtaining the attributes of the existing path and of the parent directory and for skipping descendants of the existing path.
- (NSDirectoryEnumerator) enumeratorAtURL(url, includingPropertiesForKeys:keys, options:mask, errorHandler:handler)
Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified URL. Because the enumeration is deep—that is, it lists the contents of all subdirectories—this enumerator object is useful for performing actions that involve large file-system subtrees. If the method is passed a directory on which another file system is mounted (a mount point), it traverses the mount point. This method does not resolve symbolic links encountered in the traversal process, nor does it recurse through them if they point to a directory.The NSDirectoryEnumerator class has methods for skipping descendants of the existing path and for returning the number of levels deep the current object is in the directory hierarchy being enumerated (where the directory passed to enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: is considered to be level 0).This code fragment enumerates a URL and it’s subdirectories, collecting the URLs of files (skips directories). It also demonstrates how to ignore the contents of specified directories, in this case directories named “_extras”.
- (Boolean) evictUbiquitousItemAtURL(url, error:errorOut)
Removes the local copy of the specified cloud-based item. This method does not remove the item from the cloud. It removes only the local version. You can use this method to force iCloud to download a new version of the file or directory from the server. To delete a file permanently from the user’s iCloud storage, use the regular NSFileManager routines for deleting files and directories. Remember that deleting items from iCloud cannot be undone. Once deleted, the item is gone forever.
- (Boolean) fileExistsAtPath(path)
Returns a Boolean value that indicates whether a file or directory exists at a specified path. If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns NO. If the final element in 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. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.
- (Boolean) fileExistsAtPath(path, isDirectory:isDirectory)
Returns a Boolean value that indicates whether a file or directory exists at a specified path. If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns NO. If the final element in 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. If you need to further determine if path is a package, use the isFilePackageAtPath: method of NSWorkspace.This example gets an array that identifies the fonts in the user’s fonts directory: Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.
- (const char) fileSystemRepresentationWithPath(path)
Returns a C-string representation of a given path that properly encodes Unicode strings for use by the file system. Use this method if your code calls system routines that expect C-string path arguments. If you use the C string beyond the scope of the current autorelease pool, you must copy it. This method raises an exception if path is nil or contains the empty string. This method also throws an exception if the conversion of the string fails.
- (Object) init
Returns an initialized NSFileManager instance. In iOS and in OS X 10.5 and later you can use this method to create a specific file manager instance. You might do this in situations where you want to associate a delegate with the file manager to receive notifications about the status of file-related operations.
- (Boolean) isDeletableFileAtPath(path)
Returns a Boolean value that indicates whether the invoking object appears able to delete a specified file. For a directory or file to be deletable, the current process must either be able to write to the parent directory of path or it must have the same owner as the item at path. If path is a directory, every item contained in path must be deletable by the current process.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 does not traverse symbolic links in the path.Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.
- (Boolean) isExecutableFileAtPath(path)
Returns a Boolean value that indicates whether the operating system appears able to execute a specified file. 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 executable. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.
- (Boolean) isReadableFileAtPath(path)
Returns a Boolean value that indicates whether the invoking object appears able to read a specified file. 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 readable. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.
- (Boolean) isUbiquitousItemAtURL(url)
Returns a Boolean indicating whether the item is targeted for storage in iCloud. This method reflects only whether the item should be stored in iCloud because a call was made to the setUbiquitous:itemAtURL:destinationURL:error: method with a value of YES for its flag parameter. This method does not reflect whether the file has actually been uploaded to any iCloud servers. To determine a file’s upload status, check the NSURLUbiquitousItemIsUploadedKey attribute of the corresponding NSURL object.
- (Boolean) isWritableFileAtPath(path)
Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file. 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. Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.
- (Boolean) linkItemAtPath(srcPath, toPath:dstPath, error:error)
Creates a hard link between the items at the specified paths. Use this method to create hard links between files in the current file system. If dstPath is a directory, this method creates a new directory at srcPath and then creates hard links for the items in that directory. If dstPath is (or contains) a symbolic link, the symbolic link is copied to the new location and not converted to a hard link.Prior to linking each item, the file manager asks its delegate if it should actually create the link. It does this by calling the fileManager:shouldLinkItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldLinkItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager creates the hard link. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:linkingItemAtURL:toURL: or fileManager:shouldProceedAfterError:linkingItemAtPath:toPath: method to determine how to proceed.
- (Boolean) linkItemAtURL(srcURL, toURL:dstURL, error:error)
Creates a hard link between the items at the specified URLs. Use this method to create hard links between files in the current file system. If dstURL is a directory, this method creates a new directory at srcURL and then creates hard links for the items in that directory. If dstURL is (or contains) a symbolic link, the symbolic link is copied and not converted to a hard link at srcURL.Prior to linking each item, the file manager asks its delegate if it should actually create the link. It does this by calling the fileManager:shouldLinkItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldLinkItemAtPath:toPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager creates the hard link. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:linkingItemAtURL:toURL: or fileManager:shouldProceedAfterError:linkingItemAtPath:toPath: method to determine how to proceed.
- (Array) mountedVolumeURLsIncludingResourceValuesForKeys(propertyKeys, options:options)
Returns an array of URLs that identify the mounted volumes available on the computer. This call may block if I/O is required to determine values for the requested propertyKeys.
- (Boolean) moveItemAtPath(srcPath, toPath:dstPath, error:error)
Moves the file or directory at the specified path to a new location synchronously. When moving items, the current process must have permission to read the item at srcPath and write the parent directory of dstPath. If the item at srcPath is a directory, this method moves the directory and all of its contents, including any hidden files. If an item with the same name already exists at dstPath, this method aborts the move attempt and returns an appropriate error. If the last component of srcPath is a symbolic link, only the link is moved to the new path; the item pointed to by the link remains at its current location.Prior to moving the item, the file manager asks its delegate if it should actually move it. It does this by calling the fileManager:shouldMoveItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldMoveItemAtPath:toPath: method instead. If the item being moved is a directory, the file manager notifies the delegate only for the directory itself and not for any of its contents. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager moves the file. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:movingItemAtURL:toURL: or fileManager:shouldProceedAfterError:movingItemAtPath:toPath: method to determine how to proceed.If the source and destination of the move operation are not on the same volume, this method copies the item first and then removes it from its current location. This behavior may trigger additional delegate notifications related to copying and removing individual items.
- (Boolean) moveItemAtURL(srcURL, toURL:dstURL, error:error)
Moves the file or directory at the specified URL to a new location synchronously. When moving items, the current process must have permission to read the item at srcURL and write the parent directory of dstURL. If the item at srcURL is a directory, this method moves the directory and all of its contents, including any hidden files. If an item with the same name already exists at dstURL, this method aborts the move attempt and returns an appropriate error. If the last component of srcURL is a symbolic link, only the link is moved to the new path; the item pointed to by the link remains at its current location.Prior to moving the item, the file manager asks its delegate if it should actually move it. It does this by calling the fileManager:shouldMoveItemAtURL:toURL: method; if that method is not implemented it calls the fileManager:shouldMoveItemAtPath:toPath: method instead. If the item being moved is a directory, the file manager notifies the delegate only for the directory itself and not for any of its contents. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager moves the file. If there is an error moving one out of several items, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:movingItemAtURL:toURL: or fileManager:shouldProceedAfterError:movingItemAtPath:toPath: method to determine how to proceed.If the source and destination of the move operation are not on the same volume, this method copies the item first and then removes it from its current location. This behavior may trigger additional delegate notifications related to copying and removing individual items.
- (Boolean) removeItemAtPath(path, error:error)
Removes the file or directory at the specified path. Prior to removing each item, the file manager asks its delegate if it should actually do so. It does this by calling the fileManager:shouldRemoveItemAtURL: method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the fileManager:shouldRemoveItemAtPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager proceeds to remove the file or directory. If there is an error removing an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:removingItemAtURL: or fileManager:shouldProceedAfterError:removingItemAtPath: method to determine how to proceed.
- (Boolean) removeItemAtURL(URL, error:error)
Removes the file or directory at the specified URL. Prior to removing each item, the file manager asks its delegate if it should actually do so. It does this by calling the fileManager:shouldRemoveItemAtURL: method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the fileManager:shouldRemoveItemAtPath: method instead. If the delegate method returns YES, or if the delegate does not implement the appropriate methods, the file manager proceeds to remove the file or directory. If there is an error removing an item, the file manager may also call the delegate’s fileManager:shouldProceedAfterError:removingItemAtURL: or fileManager:shouldProceedAfterError:removingItemAtPath: method to determine how to proceed.
- (Boolean) replaceItemAtURL(originalItemURL, withItemAtURL:newItemURL, backupItemName:backupItemName, options:options, resultingItemURL:resultingURL, error:error)
Replaces the contents of the item at the specified URL in a manner that insures no data loss occurs. By default, the creation date, permissions, Finder label and color, and Spotlight comments of the original item will be preserved on the resulting item.If an error occurs and the original item is not in the original location or a temporary location, the returned error object contains a user info dictionary with the NSFileOriginalItemLocationKey key. The value assigned to that key is an NSURL object with the location of the item. The error code is one of the file-related errors described in NSError Codes.
- (Boolean) setAttributes(attributes, ofItemAtPath:path, error:error)
Sets the attributes of the specified file or directory. 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. If the last component of the path is a symbolic link it is traversed.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.
- (Object) setDelegate(delegate)
Sets the delegate for the receiver. It is recommended that you assign a delegate only to file manager objects that you create explicitly using the alloc/init convention.
- (Boolean) setUbiquitous(flag, itemAtURL:url, destinationURL:destinationURL, error:errorOut)
Sets whether the item at the specified URL should be stored in the cloud. Use this method to move a file from its current location to iCloud. For files located in an app’s sandbox, this involves physically removing the file from the sandbox container. (The system extends your app’s sandbox privileges to give it access to files it moves to iCloud.) You can also use this method to move files out of iCloud and back into a local directory.Your app must have an active file presenter object configured to monitor the specified file or directory before calling this method. When you specify YES for the flag parameter, this method attempts to move the file or directory to the cloud and returns YES if it is successful. This method also notifies your file presenter of the new location of the file so that your app can continue to operate on it.Important: Do not call this method from your app’s main thread. This method performs a coordinated write operation on the file you specify, and calling this method from the main thread can trigger a deadlock with the file presenter you have monitoring the file. Instead, use a dispatch queue (other than the main thread queue) to call this method from a secondary thread. You can message your main thread after the call finishes to update the rest of your app’s data structures.
- (Boolean) startDownloadingUbiquitousItemAtURL(url, error:errorOut)
Starts downloading (if necessary) the specified item to the local system. If a cloud-based file or directory has not been downloaded yet, calling this method starts the download process. If the item exists locally, calling this method synchronizes the local copy with the version in the cloud. For a given URL, you can determine if a file is downloaded by getting the value of the NSMetadataUbiquitousItemIsDownloadedKey key. You can also use related keys to determine the current progress in downloading the file.
- (String) stringWithFileSystemRepresentation(string, length:len)
Returns an NSString object whose contents are derived from the specified C-string path. Use this method if your code receives paths as C strings from system routines.
- (Array) subpathsAtPath(path)
Returns an array of strings identifying the paths for all items in the specified directory. This method recurses the specified directory and its subdirectories. The method skips the “.” and “..” directories at each level of the recursion.This method reveals every element of the subtree at path, including the contents of file packages (such as apps, nib files, and RTFD files). This code fragment gets the contents of /System/Library/Fonts after verifying that the directory exists:
- (Array) subpathsOfDirectoryAtPath(path, error:error)
Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories. This method recurses the specified directory and its subdirectories. The method skips the “.” and “..” directories at each level of the recursion.Because this method recurses the directory’s contents, you might not want to use it in performance-critical code. Instead, consider using the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: or enumeratorAtPath: method to enumerate the directory contents yourself. Doing so gives you more control over the retrieval of items and more opportunities to abort the enumeration or perform other tasks at the same time.
- (Object) ubiquityIdentityToken
Returns an opaque token that represents the current iCloud (“ubiquity”) identity. Call this method to check if iCloud is available. You can call this method on the main thread.You can also use this method, together with the NSUbiquityIdentityDidChangeNotification notification, to detect when a user changes to a different iCloud account, or logs in or out of iCloud. When the ubiquity identity changes, the system posts that notification.You can copy or encode a ubiquity identity token, and you can compare it to previously-obtained values by using the isEqual: method.This method returns nil if ubiquity containers are unavailable because the user has disabled them, or if the user is not logged in to iCloud.Calling this method does not establish access to your app’s ubiquity containers. To establish access to a ubiquity container, call the URLForUbiquityContainerIdentifier: method. In OS X, you can instead use an NSDocument object, which establishes access automatically.
- (NSURL) URLForDirectory(directory, inDomain:domain, appropriateForURL:url, create:shouldCreate, error:error)
Locates and optionally creates the specified common directory in a domain. You typically use this method to locate one of the standard system directories, such as the Documents, Application Support or Caches directories. You can also use this method to create a new temporary directory for storing things like autosave files; to do so, specify NSItemReplacementDirectory for the directory parameter, NSUserDomainMask for the domain parameter, and a valid parent directory for the url parameter. After locating (or creating) the desired directory, this method returns the URL for that directory. If more than one appropriate directory exists in the specified domain, this method returns only the first one it finds.Passing a directory and domain pair that makes no sense (for example NSDesktopDirectory and NSNetworkDomainMask) raises an exception.
- (NSURL) URLForPublishingUbiquitousItemAtURL(url, expirationDate:outDate, error:error)
Returns a URL that can be emailed to users to allow them to download a copy of a cloud-based item. This method creates a snapshot of the specified file and places that copy in a temporary iCloud location where it can be accessed by other users using the returned URL. The snapshot reflects the contents of the file at the time the URL was generated and is not updated when subsequent changes are made to the original file in the user’s iCloud storage. The snapshot file remains available at the specified URL until the date specified in the outDate parameter, after which it is automatically deleted. Your app must have access to the network for this call to succeed.
- (NSURL) URLForUbiquityContainerIdentifier(containerID)
Returns the URL for the ubiquity (iCloud) container associated with the
specified container identifier, and establishes access to that container.
In OS X, you do not need to call this method if you use NSDocument-based
objects, because the system then calls this method automatically.You can
use the URL returned by this method to build paths to files and directories
within your app’s ubiquity container. Each app that syncs documents to the
cloud must have at least one associated ubiquity container in which to put
those files. This container can be unique to the app or shared by multiple
apps.Important: Do not call this method from your app’s main thread.
Instead, use a dispatch queue (other than the main thread queue) to call
this method from a secondary thread. In addition to writing to its own
ubiquity container, an app can write to any container directory for which
it has the appropriate permission. Each additional ubiquity container
should be listed as an additional value in the
com.apple.developer.ubiquity-container-identifiers entitlement array. To
learn how to view your development team’s unique
- (Array) URLsForDirectory(directory, inDomains:domainMask)
Returns an array of URLs for the specified common directory in the requested domains. This method is intended to locate known and common directories in the system. For example, setting the directory to NSApplicationDirectory, will return the Applications directories in the requested domain. There are a number of common directories available in the NSSearchPathDirectory, including: NSDesktopDirectory, NSApplicationSupportDirectory, and many more.