Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSFileManagerMBS class.

Next items

NSFileManagerMBS.attributesOfFileSystemForPath(item as folderitem, byref error as NSErrorMBS) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

path: A folderitem pointing to the mounted file system.
error: On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns an Dictionary object that describes the attributes of the mounted file system on which path resides, or nil if an error occurs. See File-System Attribute Keys for a description of the keys available in the dictionary.

See also:

NSFileManagerMBS.attributesOfFileSystemForPath(path as string, byref error as NSErrorMBS) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

path: Any pathname within the mounted file system.
error: On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Returns an Dictionary object that describes the attributes of the mounted file system on which path resides, or nil if an error occurs. See File-System Attribute Keys for a description of the keys available in the dictionary.

See also:

NSFileManagerMBS.attributesOfItemAtPath(item as folderitem, byref error as NSErrorMBS) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 12.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the attributes of the item at a given path.
Example
Var n as new NSFileManagerMBS
Var e as NSErrorMBS
Var d as Dictionary = n.attributesOfItemAtPath(SpecialFolder.Desktop, e)

break // check dictionary in debugger

item: The folderitem of a file or directory.
Error: If an error occurs, this is set to an actual error object containing the error information.

Return a Dictionary object that describes the attributes (file, directory, symlink, and so on) of the file specified by path. The keys in the dictionary are described in File Attribute Keys. (see NSFile* methods)

Special Considerations
This method does not traverse symbolic links. If the item at the path is a symbolic link—that is, the value of the NSFileType key in the attributes dictionary is NSFileTypeSymbolicLink—you can use the destinationOfSymbolicLinkAtPath method to retrieve the path of the item pointed to by the link. You can also use the stringByResolvingSymlinksInPath method of NSString to resolve links in the path before retrieving the item's attributes.

Available in Mac OS X v10.5 and later.

See also:

Some examples using this method:

NSFileManagerMBS.attributesOfItemAtPath(path as string, byref error as NSErrorMBS) as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 12.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the attributes of the item at a given path.

path: The path of a file or directory.
Error: If an error occurs, this is set to an actual error object containing the error information.

Return a Dictionary object that describes the attributes (file, directory, symlink, and so on) of the file specified by path. The keys in the dictionary are described in File Attribute Keys. (see NSFile* methods)

Special Considerations
This method does not traverse symbolic links. If the item at the path is a symbolic link—that is, the value of the NSFileType key in the attributes dictionary is NSFileTypeSymbolicLink—you can use the destinationOfSymbolicLinkAtPath method to retrieve the path of the item pointed to by the link. You can also use the stringByResolvingSymlinksInPath method of NSString to resolve links in the path before retrieving the item's attributes.

Available in Mac OS X v10.5 and later.

See also:

NSFileManagerMBS.destinationOfSymbolicLinkAtPath(file as folderitem, byref error as NSErrorMBS) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 16.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the path of the item pointed to by a symbolic link.

file: The folderitem of a file or directory. Be aware that Xojo may already have resolved the symlink!
error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns a string containing the path of the directory or file to which the symbolic link path refers, or "" upon failure. If the symbolic link is specified as a relative path, that relative path is returned.

See also:

NSFileManagerMBS.destinationOfSymbolicLinkAtPath(path as string, byref error as NSErrorMBS) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 16.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the path of the item pointed to by a symbolic link.
Example
Var f as new NSFileManagerMBS
Var e as NSErrorMBS

Var p as string = f.destinationOfSymbolicLinkAtPath("/tmp", e)

if e = nil then
MsgBox p
else
MsgBox e.LocalizedDescription
end if

path: The path of a file or directory.
error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns a string containing the path of the directory or file to which the symbolic link path refers, or "" upon failure. If the symbolic link is specified as a relative path, that relative path is returned.

See also:

NSFileManagerMBS.displayName(path as folderitem) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the display name of the file or directory at a specified path.

path: The path of a file or directory.

The name of the file or directory at path in a localized form appropriate for presentation to the user. If there is no file or directory at path, or if an error occurs, returns path as is.

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.

NSFileManagerMBS.evictUbiquitousItem(item as folderitem, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the local copy of the specified cloud-based item.

item: Specify the file or directory in iCloud storage.
error: If an error occurs, this pointer is set to an NSError object containing information about the error.

Returns true if the local item was removed successfully or false if it was not. If false is returned, an NSError object describing the error is returned in the error parameter.

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.

Available in Mac OS X v10.7 and later.

NSFileManagerMBS.fileExists(path as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether a file or directory exists at a specified path.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Desktop.Child("notes.rtf")

MsgBox "File exists: "+str(m.fileExists(f))

path: The path of the file or directory. I

Returns true if a file at the specified path exists or false if the file's does not exist or its existence could not be determined.

If the file at path is inaccessible to your application, perhaps because one or more parent directories are inaccessible, this method returns false. If the final element in path specifies a symbolic link, this method traverses the link and returns true or false 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, File Operations, and Interprocess Communication in Secure Coding Guide.
http://developer.apple.com/library/mac/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585

See also:

NSFileManagerMBS.fileExists(path as folderitem, byref isDirectory as boolean) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether a file or directory exists at a specified path.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Desktop

Var directory as Boolean
MsgBox "File exists: "+str(m.fileExists(f, directory))+" and is Directory: "+str(Directory)

path: The path of a file or directory.
isDirectory: Upon return, contains true if path is a directory or if the final path element is a symbolic link that points to a directory, otherwise contains false. If path doesn't exist, the return value is undefined.

Returns true if a file at the specified path exists or false if the file's does not exist or its existence could not be determined.

If the file at path is inaccessible to your application, perhaps because one or more parent directories are inaccessible, this method returns false. If the final element in path specifies a symbolic link, this method traverses the link and returns true or false 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 NSWorkspaceMBS.

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, File Operations, and Interprocess Communication in Secure Coding Guide.
http://developer.apple.com/library/mac/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585

See also:

NSFileManagerMBS.FileForUbiquityContainerIdentifier(containerIdentifier as string) as folderitem

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the iCloud directory associated with the specified container ID.

containerID: Specify the container ID of the cloud-based storage container. The string you specify must not contain wildcards and must be of the form <TEAMID>.<CONTAINER>, where <TEAMID> is your development team ID and <CONTAINER> describes the bundle identifier of the container you want to access. The container identifiers for your application must be declared in the com.apple.developer.ubiquity-container-identifiers entitlement.
If you specify "", this method returns the first container listed in the com.apple.developer.ubiquity-container-identifiers entitlement.

Returns a folderitem pointing to the specified container directory or nil if the container could not be located or if iCloud storage is unavailable for the current user or device.

You can use the folderitem returned by this method to build paths to files and directories in the user's iCloud storage. Each application that syncs documents to the cloud must have at least one associated container directory in which to put those files. This container directory can be unique to the application or shared by multiple applications. You use this method to retrieve the folderitem for that container directory.

In addition to writing to its own container directory, an application can write to any container directory for which it has the appropriate permission. Each additional container directory should be listed as an additional value in the com.apple.developer.ubiquity-container-identifiers entitlement.

Note: The development team ID that precedes each container ID string is the unique identifier associated with your development team. You can find this string in the Member Center of the Apple Developer website (http://developer.apple.com/membercenter). From the Member Center home page, select the Your Account tab and then select Organization Profile from the column on the left of that tab. Your team's identifier is in the Company/Organization ID field.
The first time you call this method for a given container directory, iOS extends your application sandbox to include that container directory. Thus, it is important that you call this method at least once before trying to search for files in iCloud. And if your application accesses multiple container directories, you should call the method once for each directory.

Available in Mac OS X v10.7 and later.
FileForUbiquityContainerIdentifier returns folderitem while URLForUbiquityContainerIdentifier returns URL string.

Some examples using this method:

NSFileManagerMBS.homeDirectoryForUser(Name as string) as FolderItem

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the home directory for the specified user.

userName: The username of the owner of the desired home directory.

Returns the folderitem containing the location of the specified user’s home directory, or nil if no such user exists or the user’s home directory is not available.

NSFileManagerMBS.isDeletableFile(path as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether the invoking object appears able to delete a specified file.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Desktop.Child("notes.rtf")

MsgBox "Can delete: "+str(m.isDeletableFile(f))

path: A file path.

Returns true if the current process has delete privileges for the file at path; otherwise false if the process does not have delete privileges or the existence of the file could not be determined.

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 application, perhaps because it does not have search privileges for one or more parent directories, this method returns false. 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, File Operations, and Interprocess Communication in Secure Coding Guide.
http://developer.apple.com/library/mac/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585

NSFileManagerMBS.isExecutableFile(path as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether the operating system appears able to execute a specified file.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Desktop.Child("notes.rtf")

MsgBox "Can execute: "+str(m.isExecutableFile(f))

path: A file path.

Returns true if the current process has execute privileges for the file at path; otherwise false if the process does not have execute privileges or the existence of the file could not be determined.

If the file at path is inaccessible to your application, perhaps because it does not have search privileges for one or more parent directories, this method returns false. 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, File Operations, and Interprocess Communication in Secure Coding Guide:
http://developer.apple.com/library/mac/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585

NSFileManagerMBS.isReadableFile(path as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether the invoking object appears able to read a specified file.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Desktop.Child("notes.rtf")

MsgBox "Can read: "+str(m.isReadableFile(f))

path: A file path.

Returns true if the current process has read privileges for the file at path; otherwise false if the process does not have read privileges or the existence of the file could not be determined.

If the file at path is inaccessible to your application, perhaps because it does not have search privileges for one or more parent directories, this method returns false. 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, File Operations, and Interprocess Communication in Secure Coding Guide.
http://developer.apple.com/library/mac/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585

NSFileManagerMBS.isUbiquitousItem(item as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean indicating whether the item is targeted for storage in iCloud.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Desktop.Child("notes.rtf")

MsgBox "Is in iCloud: "+str(m.isUbiquitousItem(f))

item: Specify the folderitem for the file or directory whose status you want to check.

Returns true if the item is targeted for iCloud storage or false if it is not. This method also returns false if no item exists at url.

This method reflects only whether the item should be stored in iCloud because a call was made to the setUbiquitous method with a value of true 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 IsUploadedMBS function in the folderitem class.

Available in Mac OS X v10.7 and later.

See also:

NSFileManagerMBS.isUbiquitousItem(URL as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean indicating whether the item is targeted for storage in iCloud.

item: Specify the URL for the file or directory whose status you want to check.

Returns true if the item is targeted for iCloud storage or false if it is not. This method also returns false if no item exists at url.

This method reflects only whether the item should be stored in iCloud because a call was made to the setUbiquitous method with a value of true 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 IsUploadedMBS function in the folderitem class.

Available in Mac OS X v10.7 and later.

See also:

NSFileManagerMBS.isWritableFile(path as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Desktop.Child("notes.rtf")

MsgBox "Can write: "+str(m.isWritableFile(f))

path: A file path.

Returns true if the current process has write privileges for the file at path; otherwise false if the process does not have write privileges or the existence of the file could not be determined.

If the file at path is inaccessible to your application, perhaps because it does not have search privileges for one or more parent directories, this method returns false. 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, File Operations, and Interprocess Communication in Secure Coding Guide:
http://developer.apple.com/library/mac/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585

NSFileManagerMBS.linkItem(source as folderItem, dest as folderItem, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 13.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a hard link between the items at the specified paths.

Source: The path that specifies the item you wish to link to. The value in this parameter must not be nil.
Dest: The path that identifies the location where the link will be created. The value in this parameter must not be nil.
error: If an error occurs, this pointer is set to an actual error object containing the error information.

Returns true if the hard link was created or NO if an error occurred. This method also returns false if a file, directory, or link already exists at dstPath.

Use this method to create hard links between files in the current file system. If Source is a directory, this method creates a new directory at Dest and then creates hard links for the items in that directory. If Source is (or contains) a symbolic link, the symbolic link is copied to the new location and not converted to a hard link.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.linkItem(sourcePath as String, destPath as String, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 19.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a hard link between the items at the specified paths.

Source: The path that specifies the item you wish to link to. The value in this parameter must not be nil.
Dest: The path that identifies the location where the link will be created. The value in this parameter must not be nil.
error: If an error occurs, this pointer is set to an actual error object containing the error information.

Returns true if the hard link was created or NO if an error occurred. This method also returns false if a file, directory, or link already exists at dstPath.

Use this method to create hard links between files in the current file system. If Source is a directory, this method creates a new directory at Dest and then creates hard links for the items in that directory. If Source is (or contains) a symbolic link, the symbolic link is copied to the new location and not converted to a hard link.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.moveItem(source as folderItem, dest as folderItem, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 13.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Moves the file or directory at the specified path to a new location synchronously.

source: The path to the file or directory you want to move. This parameter must not be nil.
dest: The new path for the item in Source. This path must include the name of the file or directory in its new location. This parameter must not be nil.
error: If an error occurs, this is set to an actual error object containing the error information.

Returns true if the item was moved successfully or the file manager's delegate aborted the operation deliberately. Returns NO if an error occurred.

When moving items, the current process must have permission to read the item at Source and write the parent directory of Dest. If the item at Source 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 Dest, this method aborts the move attempt and returns an appropriate error. If the last component of Source 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.

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.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.moveItem(sourcePath as String, destPath as String, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 19.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Moves the file or directory at the specified path to a new location synchronously.

source: The path to the file or directory you want to move. This parameter must not be nil.
dest: The new path for the item in Source. This path must include the name of the file or directory in its new location. This parameter must not be nil.
error: If an error occurs, this is set to an actual error object containing the error information.

Returns true if the item was moved successfully or the file manager's delegate aborted the operation deliberately. Returns NO if an error occurred.

When moving items, the current process must have permission to read the item at Source and write the parent directory of Dest. If the item at Source 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 Dest, this method aborts the move attempt and returns an appropriate error. If the last component of Source 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.

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.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.removeItem(file as folderitem, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 13.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the file or directory at the specified path.

path: A path string indicating the file or directory to remove. If the path specifies a directory, the contents of that directory are recursively removed.
error: If an error occurs, this is set to an actual error object containing the error information.

Returns true if the item was removed successfully or if path was nil. Returns false if an error occurred. If the delegate aborts the operation for a file, this method returns true. However, if the delegate aborts the operation for a directory, this method returns false.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.removeItem(path as string, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 13.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the file or directory at the specified path.

path: A path string indicating the file or directory to remove. If the path specifies a directory, the contents of that directory are recursively removed.
error: If an error occurs, this is set to an actual error object containing the error information.

Returns true if the item was removed successfully or if path was nil. Returns false if an error occurred. If the delegate aborts the operation for a file, this method returns true. However, if the delegate aborts the operation for a directory, this method returns false.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.replaceItem(originalItem as FolderItem, newItem as FolderItem, backupItemName as String, options as integer, byref resultingItem as FolderItem, byref error as NSErrorMBS) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 19.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Replaces the contents of the item at the specified URL in a manner that ensures no data loss occurs.
Example
Var fileManager As New NSFileManagerMBS

Var source As FolderItem = SpecialFolder.Desktop.Child("test.rtf")
Var dest As FolderItem = SpecialFolder.Desktop.Child("dest.rtf")

Var result As Boolean
Var output As FolderItem
Var error As NSErrorMBS

result = fileManager.replaceItemAtURL(dest, source, "", 0, output, error)

If result Then
MsgBox output.NativePath
Else
MsgBox error.LocalizedDescription
End If

originalItem: The item containing the content you want to replace.
newItem: The item containing the new content for originalItem. It is recommended that you put this item in a temporary directory as provided by the OS. If a temporary directory is not available, put this item in a uniquely named directory that is in the same directory as the original item.
backupItemName: If provided, the name used to create a backup of the original item.
The backup is automatically placed in the same directory as the original item. If an error occurs during the creation of the backup item, the operation fails. If there is already an item with the same name as the backup item, that item will be removed.
The backup item will be removed in the event of success unless the NSFileManagerItemReplacementWithoutDeletingBackupItem option is provided in options.
options: The options to use during the replacement. Typically, you pass NSFileManagerItemReplacementUsingNewMetadataOnly for this parameter, which uses only the metadata from the new item. You can also combine the options described in NSFileManagerItemReplacementOptions using the C-bitwise OR operator.
resultingItem: On input, a variale for a folderitem variable. When the item is replaced, this variable is set to the folderitem of the new item. If no new file system object is required, the folderitem in this parameter may be the same passed to the originalItem parameter. However, if a new file system object is required, the folderitem may be different. For example, replacing an RTF document with an RTFD document requires the creation of a new file.
error: On input, a variable for an error object. If an error occurs, this variable is set to an error object containing the error information.

Returns true if the replacement was successful or false if an error occurred.

By default, the creation date, permissions, Finder label and color, and Spotlight comments of the original item are preserved on the new item. You can configure which metadata is preserved using the options parameter.
This method works only when the originalItem and newItem parameters are located on the same volume. Attempting to call this method by passing originalItem and newItem parameters that have locations on different volumes results in an error. Instead, you can call the URLForDirectory method, passing NSItemReplacementDirectory as the search path directory, to get a temporary URL on the destination's volume that is suitable for use with this method.
If an error occurs and the original item is not in the original location or a temporary location, the resulting error object contains a user info dictionary with the key "NSFileOriginalItemLocationKey". The value assigned to that key is an URL with the location of the item. The error code is one of the file-related errors described in NSError Codes.

Some examples using this method:

NSFileManagerMBS.replaceItemAtURL(originalItemURL as string, newItemURL as String, backupItemName as String, options as integer, byref resultingURL as String, byref error as NSErrorMBS) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 19.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Replaces the contents of the item at the specified URL in a manner that ensures no data loss occurs.

originalItemURL: The item containing the content you want to replace.
newItemURL: The item containing the new content for originalItemURL. It is recommended that you put this item in a temporary directory as provided by the OS. If a temporary directory is not available, put this item in a uniquely named directory that is in the same directory as the original item.
backupItemName: If provided, the name used to create a backup of the original item.
The backup is automatically placed in the same directory as the original item. If an error occurs during the creation of the backup item, the operation fails. If there is already an item with the same name as the backup item, that item will be removed.
The backup item will be removed in the event of success unless the NSFileManagerItemReplacementWithoutDeletingBackupItem option is provided in options.
options: The options to use during the replacement. Typically, you pass NSFileManagerItemReplacementUsingNewMetadataOnly for this parameter, which uses only the metadata from the new item. You can also combine the options described in NSFileManagerItemReplacementOptions using the C-bitwise OR operator.
resultingURL: On input, a variale for an URL variable. When the item is replaced, this variable is set to the URL of the new item. If no new file system object is required, the URL object in this parameter may be the same passed to the originalItemURL parameter. However, if a new file system object is required, the URL object may be different. For example, replacing an RTF document with an RTFD document requires the creation of a new file.
error: On input, a variable for an error object. If an error occurs, this variable is set to an error object containing the error information.

Returns true if the replacement was successful or false if an error occurred.

By default, the creation date, permissions, Finder label and color, and Spotlight comments of the original item are preserved on the new item. You can configure which metadata is preserved using the options parameter.
This method works only when the originalItemURL and newItemURL parameters are located on the same volume. Attempting to call this method by passing originalItemURL and newItemURL parameters that have locations on different volumes results in an error. Instead, you can call the URLForDirectory method, passing NSItemReplacementDirectory as the search path directory, to get a temporary URL on the destination's volume that is suitable for use with this method.
If an error occurs and the original item is not in the original location or a temporary location, the resulting error object contains a user info dictionary with the key "NSFileOriginalItemLocationKey". The value assigned to that key is an URL with the location of the item. The error code is one of the file-related errors described in NSError Codes.

NSFileManagerMBS.setAttributes(attributesDic as dictionary, item as folderitem, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 12.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the attributes of the specified file or directory.

attributes: A dictionary containing as keys the attributes to set for path and as values the corresponding value for the attribute. You can set the following attributes: 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.
item: The folderitem of a file or directory.
error: If an error occurs, this is set to an actual error object containing the error information.

Returns true if all changes succeed. If any change fails, returns false, but it is undefined whether any changes actually occurred.

Discussion
As in the POSIX standard, the application 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.

Available in Mac OS X v10.5 and later.

See also:

NSFileManagerMBS.setAttributes(attributesDic as dictionary, path as string, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 12.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the attributes of the specified file or directory.

attributes: A dictionary containing as keys the attributes to set for path and as values the corresponding value for the attribute. You can set the following attributes: 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.
path: The path of a file or directory.
error: If an error occurs, this is set to an actual error object containing the error information.

Returns true if all changes succeed. If any change fails, returns false, but it is undefined whether any changes actually occurred.

Discussion
As in the POSIX standard, the application 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.

Available in Mac OS X v10.5 and later.

See also:

Next items

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...