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
dim n as new NSFileManagerMBS
dim e as NSErrorMBS
dim 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.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
dim m as new NSFileManagerMBS
dim 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
dim 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
dim f as FolderItem = SpecialFolder.Desktop.Child("test.rtf")
dim d as FolderItem = SpecialFolder.Desktop.Child("output.rtf")
dim 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
dim m as new NSFileManagerMBS
dim file as FolderItem = SpecialFolder.Desktop.Child("test.rtf")
dim destfile as FolderItem = SpecialFolder.Desktop.Child("Notes.rtf")
dim 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:

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
dim f as new NSFileManagerMBS
dim e as NSErrorMBS

dim 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
dim m as new NSFileManagerMBS
dim 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
dim m as new NSFileManagerMBS
dim f as FolderItem = SpecialFolder.Desktop

dim 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
dim m as new NSFileManagerMBS
dim 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
dim m as new NSFileManagerMBS
dim 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

Next items

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


The biggest plugin in space...