Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSFileManagerMBS class.

NSFileManagerMBS.changeCurrentDirectory(folder 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
Changes the path of the current working directory to the specified path.
Example
Var m as new NSFileManagerMBS
Var f as FolderItem = SpecialFolder.Applications
if m.changeCurrentDirectory(f) then
MsgBox m.currentDirectory.NativePath
end if

folder: The path of the directory to which to change.

Returns true if successful, otherwise false.

All relative pathnames refer implicitly to the current working directory. Changing the current working directory affects only paths created in the current process.

See also:

NSFileManagerMBS.changeCurrentDirectory(path as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Changes the path of the current working directory to the specified path.
Example
Var m as new NSFileManagerMBS
if m.changeCurrentDirectory("/Users") then
MsgBox m.currentDirectoryPath
end if

path: The path of the directory to which to change.

Returns true if successful, otherwise false.

All relative pathnames refer implicitly to the current working directory. Changing the current working directory affects only paths created in the current process.

See also:

NSFileManagerMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The constructor.

NSFileManagerMBS.containerFolderForSecurityApplicationGroupIdentifier(groupIdentifier as string) as folderItem

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

As explained in App Sandbox Design Guide, groups of sandboxed apps that need to share files and other information can request a container directory as part of their entitlements. These directories are stored in ~/Library/Group Containers/.

When called with a valid group identifier, this method returns the location of that directory as an folderitem. This method also creates the directory if it does not yet exist.

Important: Your app must have a com.apple.security.application-groups entitlement for the specified application group.

Available in OS X v10.8 and later.

NSFileManagerMBS.containerURLForSecurityApplicationGroupIdentifier(groupIdentifier as string) as string

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

As explained in App Sandbox Design Guide, groups of sandboxed apps that need to share files and other information can request a container directory as part of their entitlements. These directories are stored in ~/Library/Group Containers/.

When called with a valid group identifier, this method returns the location of that directory as an URL. This method also creates the directory if it does not yet exist.

Important: Your app must have a com.apple.security.application-groups entitlement for the specified application group.

Available in OS X v10.8 and later.

NSFileManagerMBS.contentsEqual(path1 as folderitem, path2 as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents.

path1: The path of a file or directory to compare with the contents of path2.
path2: The path of a file or directory to compare with the contents of path1.

Returns true if file or directory specified in path1 has the same contents as that specified in path2, otherwise false.

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.

NSFileManagerMBS.copyItem(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
Copies the item at the specified path to a new location synchronously.

Source: The path to the file or directory you want to move.
Dest: The path at which to place the copy of srcPath. This path must include the name of the file or directory in its new location.
error: If an error occurs, this is set to an actual error object containing the error information.

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

When copying items, the current process must have permission to read the file or directory at Source and write the parent directory of Dest. If the item at Source 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 Dest, 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.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.copyItem(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
Copies the item at the specified path to a new location synchronously.

Source: The path to the file or directory you want to move.
Dest: The path at which to place the copy of srcPath. This path must include the name of the file or directory in its new location.
error: If an error occurs, this is set to an actual error object containing the error information.

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

When copying items, the current process must have permission to read the file or directory at Source and write the parent directory of Dest. If the item at Source 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 Dest, 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.

Available in OS X v10.5 and later.

See also:

NSFileManagerMBS.copyItemMT(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 18.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Copies the item at the specified path to a new location synchronously.
Example
Var f as FolderItem = SpecialFolder.Desktop.Child("test.rtf")
Var d as FolderItem = SpecialFolder.Desktop.Child("output.rtf")
Var e as NSErrorMBS

if not NSFileManagerMBS.defaultManager.copyItemMT(f,d,e) then
MsgBox e.LocalizedDescription
else
MsgBox "OK"
end if

Source: The path to the file or directory you want to move.
Dest: The path at which to place the copy of srcPath. This path must include the name of the file or directory in its new location.
error: If an error occurs, this is set to an actual error object containing the error information.

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

When copying items, the current process must have permission to read the file or directory at Source and write the parent directory of Dest. If the item at Source 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 Dest, 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.

Available in OS X v10.5 and later.

The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.

See also:

NSFileManagerMBS.copyItemMT(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
Copies the item at the specified path to a new location synchronously.

Source: The path to the file or directory you want to move.
Dest: The path at which to place the copy of srcPath. This path must include the name of the file or directory in its new location.
error: If an error occurs, this is set to an actual error object containing the error information.

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

When copying items, the current process must have permission to read the file or directory at Source and write the parent directory of Dest. If the item at Source 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 Dest, 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.

Available in OS X v10.5 and later.

The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.

See also:

NSFileManagerMBS.createDirectory(Path as folderItem, createIntermediates as boolean = true, attrs as Dictionary = nil, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a directory with given attributes at the specified path.

path: A folderitme identifying the directory to create. You may specify a full path or a path that is relative to the current working directory. This parameter must not be nil.
createIntermediates: If true, this method creates any non-existent parent directories as part of creating the directory in path. If NO, this method fails if any of the intermediate parent directories does not exist. This method also fails if any of the intermediate path elements corresponds to a file and not a directory.
attributes: The file attributes for the new directory and any newly created intermediate directories. You can set the owner and group numbers, file permissions, and modification date. If you specify nil for this parameter or omit a particular value, one or more default values are used as described in the discussion. For a list of keys you can include in this dictionary, see Constants. Some of the keys, such as NSFileHFSCreatorCode and NSFileHFSTypeCode, do not apply to directories.
error: If an error occurs, this variable is set to an actual error object containing the error information.

Returns true if the directory was created, true if createIntermediates is set and the directory already exists, or false if an error occurred.

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.

See also:

NSFileManagerMBS.createDirectory(Path as String, createIntermediates as boolean = true, attrs as Dictionary = nil, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a directory with given attributes at the specified path.

path: A path string identifying the directory to create. You may specify a full path or a path that is relative to the current working directory. This parameter must not be nil.
createIntermediates: If true, this method creates any non-existent parent directories as part of creating the directory in path. If NO, this method fails if any of the intermediate parent directories does not exist. This method also fails if any of the intermediate path elements corresponds to a file and not a directory.
attributes: The file attributes for the new directory and any newly created intermediate directories. You can set the owner and group numbers, file permissions, and modification date. If you specify nil for this parameter or omit a particular value, one or more default values are used as described in the discussion. For a list of keys you can include in this dictionary, see Constants. Some of the keys, such as NSFileHFSCreatorCode and NSFileHFSTypeCode, do not apply to directories.
error: If an error occurs, this variable is set to an actual error object containing the error information.

Returns true if the directory was created, true if createIntermediates is set and the directory already exists, or false if an error occurred.

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.

See also:

NSFileManagerMBS.createFile(Path as folderItem, contents as MemoryBlock, attrs as Dictionary = nil) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a file with the specified content and attributes at the given location.

path: The folderitem for the new file.
contents: A data object containing the contents of the new file.
attributes: A dictionary containing the attributes to associate with the new file. You can use these attributes to set the owner and group numbers, file permissions, and modification date. For a list of keys, see NSFileAttributeKey. If you specify nil for attributes, the file is created with a set of default attributes.

Returns true if the operation was successful or if the item already exists, otherwise false.

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.

See also:

NSFileManagerMBS.createFile(Path as String, contents as MemoryBlock, attrs as Dictionary = nil) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method iCloud MBS MacCocoa Plugin 18.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a file with the specified content and attributes at the given location.

path: The path for the new file.
contents: A data object containing the contents of the new file.
attributes: A dictionary containing the attributes to associate with the new file. You can use these attributes to set the owner and group numbers, file permissions, and modification date. For a list of keys, see NSFileAttributeKey. If you specify nil for attributes, the file is created with a set of default attributes.

Returns true if the operation was successful or if the item already exists, otherwise false.

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.

See also:

NSFileManagerMBS.createSymbolicLink(file as folderitem, destFile 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
Creates a symbolic link at the specified URL that points to an item at the given URL.
Example
Var m as new NSFileManagerMBS
Var file as FolderItem = SpecialFolder.Desktop.Child("test.rtf")
Var destfile as FolderItem = SpecialFolder.Desktop.Child("Notes.rtf")
Var error as NSErrorMBS

if m.createSymbolicLink(file, destfile, error) then
MsgBox "OK"
else
MsgBox "Error: "+error.localizedDescription
end if

file: The path at which to create the new symbolic link. The last path component is used as the name of the link.
destFile: The path that contains the item to be pointed to by the link. In other words, this is the destination of the link.
error: If an error occurs, upon return contains an NSError object that describes the problem.

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

This method does not traverse symbolic links contained in either path or destPath.

Available in Mac OS X v10.5 and later.
As of Mac OS X 10.7 tests here, it seems like an alias file is created, not a symbolic link.

See also:

NSFileManagerMBS.createSymbolicLink(path 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 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a symbolic link that points to the specified destination.

path: The path at which to create the new symbolic link. The last path component is used as the name of the link.
destPath: The path that contains the item to be pointed to by the link. In other words, this is the destination of the link.
error: If an error occurs, upon return contains an NSError object that describes the problem.

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

This method does not traverse symbolic links contained in either path or destPath.

Available in Mac OS X v10.5 and later.
As of Mac OS X 10.7 tests here, it seems like an alias file is created, not a symbolic link.

See also:

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


The biggest plugin in space...