Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSFileManagerMBS class.

NSFileManagerMBS.fileManagerWithAuthorization(authorization as NSWorkspaceAuthorizationMBS) as NSFileManagerMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 19.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Initializes a file manager object that is authorized to perform privileged file system operations.

Returns nil in case of errors.

This method returns an NSFileManagerMBS instance that can perform file system operations previously allowed by the user via NSWorkspaceMBS.requestAuthorization. Each NSWorkspaceAuthorizationMBS you receive requires creating a new NSFileManagerMBS instance using this method.

Only the following NSFileManagerMBS methods currently take advantage of an authorization:

  • createSymbolicLink (NSWorkspaceAuthorizationTypeCreateSymbolicLink)
  • setAttributes (NSWorkspaceAuthorizationTypeSetAttributes)
  • replaceItem (NSWorkspaceAuthorizationTypeReplaceFile)
Note that an NSWorkspaceAuthorizationTypeSetAttributes authorization only enables setAttributes to modify the following attributes:
  • NSFileOwnerAccountID
  • NSFileGroupOwnerAccountID
  • NSFilePosixPermissions
Also note that for replaceItem, the backupItemName and options parameters will be ignored.

These methods may also fail with any of the following errors
  • NSWorkspaceAuthorizationInvalidError: The provided NSWorkspaceAuthorization expired or is invalid.
  • NSFileWriteUnknownError: The application failed to communicate with a helper process, or a file system error occurred.
  • NSFileWriteNoPermissionError: The operation failed for any other reason, including the user denying access to the resource, or access to a resource is denied by system policy.
All other NSFileManager methods invoked on this instance will behave normally.
The app using this may need code signature with com.apple.developer.security.privileged-file-operations entitlement for the sandboxed application and may need to be in applications folder.

Some examples using this method:

NSFileManagerMBS.lastPathComponent(pathOrURL as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the last path component of a file URL or file path.

Available in Mac OS X v10.6 and later.

NSFileManagerMBS.pathExtension(pathOrURL as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the path extension of a file URL or file path.

Available in Mac OS X v10.6 and later.

NSFileManagerMBS.stringByAbbreviatingWithTildeInPath(path as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string that replaces the current home directory portion of the current path with a tilde (~) character.

A new string based on the current string object. If the new string specifies a file in the current home directory, the home directory portion of the path is replaced with a tilde (~) character. If the string does not specify a file in the current home directory, this method returns a new string object whose path is unchanged from the path in the current string.

Note that this method only works with file paths. It does not work for string representations of URLs.

For sandboxed apps in OS X, the current home directory is not the same as the user’s home directory. For a sandboxed app, the home directory is the app’s home directory. So if you specified a path of /Users/<current_user>/file.txt for a sandboxed app, the returned path would be unchanged from the original. However, if you specified the same path for an app not in a sandbox, this method would replace the /Users/<current_user> portion of the path with a tilde.

NSFileManagerMBS.stringByAppendingPathComponent(path as string, Component as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string made by appending to the receiver a given string.

The following table illustrates the effect of this method on a variety of different paths, assuming that aString is supplied as “scratch.tiff”:

Receiver’s String ValueResulting String
“/tmp”“/tmp/scratch.tiff”
“/tmp/”“/tmp/scratch.tiff”
“/”“/scratch.tiff”
“” (an empty string)“scratch.tiff”

Note that this method only works with file paths (not, for example, string representations of URLs).

NSFileManagerMBS.stringByAppendingPathExtension(path as string, Extension as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string made by appending to the receiver an extension separator followed by a given extension.

The following table illustrates the effect of this method on a variety of different paths, assuming that ext is supplied as "tiff":

Receiver’s String ValueResulting String
“/tmp/scratch.old”“/tmp/scratch.old.tiff”
“/tmp/scratch.”“/tmp/scratch..tiff”
“/tmp/”“/tmp.tiff”
“scratch”“scratch.tiff”

Note that adding an extension to "/tmp/" causes the result to be "/tmp.tiff" instead of "/tmp/.tiff". This difference is because a file named ".tiff" is not considered to have an extension, so the string is appended to the last nonempty path component.

Note that this method only works with file paths (not, for example, string representations of URLs).

Special Considerations
Prior to OS X v10.9 this method did not allow you to append file extensions to filenames starting with the tilde character (~).

NSFileManagerMBS.stringByDeletingLastPathComponent(path as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string made by deleting the last path component from the receiver, along with any final path separator.

A new string made by deleting the last path component from the receiver, along with any final path separator. If the receiver represents the root path it is returned unaltered.

The following table illustrates the effect of this method on a variety of different paths:

Receiver’s String ValueResulting String
“/tmp/scratch.tiff”“/tmp”
“/tmp/lock/”“/tmp”
“/tmp/”“/”
“/tmp”“/”
“/”“/”
“scratch.tiff”“” (an empty string)

Note that this method only works with file paths (not, for example, string representations of URLs).

NSFileManagerMBS.stringByDeletingPathExtension(path as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string made by deleting the extension (if any, and only the last) from the receiver.

A new string made by deleting the extension (if any, and only the last) from the receiver. Strips any trailing path separator before checking for an extension. If the receiver represents the root path, it is returned unaltered.

The following table illustrates the effect of this method on a variety of different paths:

Receiver’s String ValueResulting String
“/tmp/scratch.tiff”“/tmp/scratch”
“/tmp/”“/tmp”
“scratch.bundle/”“scratch”
“scratch..tiff”“scratch.”
“.tiff”“.tiff”
“/”“/”

Note that attempting to delete an extension from ".tiff" causes the result to be @".tiff" instead of an empty string. This difference is because a file named ".tiff" is not considered to have an extension, so nothing is deleted. Note also that this method only works with file paths (not, for example, string representations of URLs).

NSFileManagerMBS.stringByExpandingTildeInPath(path as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string made by expanding the initial component of the receiver to its full path value.

A new string made by expanding the initial component of the receiver, if it begins with “~” or “~user”, to its full path value. Returns a new string matching the receiver if the receiver’s initial component can’t be expanded.

Note that this method only works with file paths (not, for example, string representations of URLs).

NSFileManagerMBS.stringByResolvingSymlinksInPath(path as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string made from the receiver by resolving all symbolic links and standardizing path.

A new string made by resolving all symbolic links, then removing extraneous path components. For absolute paths, all symbolic links are guaranteed to be removed. For relative paths, symbolic links that can’t be resolved are left unresolved in the returned string.

Returns self if an error occurs.

Note that this method only works with file paths (not, for example, string representations of URLs).

NSFileManagerMBS.stringByStandardizingPath(path as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 16.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new string made by removing extraneous path components from the receiver.

A new string made by performing the following operations:

  • Expanding an initial tilde expression using stringByExpandingTildeInPath.
  • Removing an initial component of “/private/var/automount”, “/var/automount”, or “/private” from the path, if the result still indicates an existing file or directory (checked by consulting the file system).
  • Reducing empty components and references to the current directory (that is, the sequences “//” and “/./”) to single path separators.
  • Removing a trailing slash from the last component.
  • For absolute paths only, resolving references to the parent directory (that is, the component “..”) to the real parent directory if possible using stringByResolvingSymlinksInPath. For relative paths, references to the parent directory are left in place.
  • Returns self if an error occurs.
Note that the path returned by this method may still have symbolic link components in it. Note also that this method only works with file paths (not, for example, string representations of URLs).

NSFileManagerMBS.URLByAppendingPathComponent(URL as string, pathComponent as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new URL made by appending a path component to the original URL.

pathComponent: The path component to add to the URL.

Returns a new URL with pathComponent appended.

If the original URL does not end with a forward slash and pathComponent does not begin with a forward slash, a forward slash is inserted between the two parts of the returned URL, unless the original URL is the empty string.

Available in Mac OS X v10.6 and later.

See also:

NSFileManagerMBS.URLByAppendingPathComponent(URL as string, pathComponent as string, isDirectory as boolean) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new URL made by appending a path component to the original URL, along with a trailing slash if the component is designated a directory.

pathComponent: The path component to add to the URL.
isDirectory: If true, a trailing slash is appended after pathComponent.
Returns a new URL with pathComponent appended.

If the original URL does not end with a forward slash and pathComponent does not begin with a forward slash, a forward slash is inserted between the two parts of the returned URL, unless the original URL is the empty string.

Available in Mac OS X v10.7 and later.

See also:

NSFileManagerMBS.URLByAppendingPathExtension(URL as string, pathExtension as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new URL made by appending a path extension to the original URL.

pathExtension: The path extension to add to the URL.

Returns a new URL with pathExtension appended.

If the original URL ends with one or more forward slashes, these are removed from the returned URL. A period is inserted between the two parts of the new URL.
Available in Mac OS X v10.6 and later.

NSFileManagerMBS.URLByDeletingLastPathComponent(URL as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new URL made by deleting the last path component from the original URL.

If the original URL represents the root path, the returned URL is identical. Otherwise, if the original URL has only one path component, the new URL is the empty string.
Available in Mac OS X v10.6 and later.

NSFileManagerMBS.URLByDeletingPathExtension(URL as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new URL made by deleting the path extension, if any, from the original URL.

If the original URL represents the root path, the returned URL is identical. If the URL has multiple path extensions, only the last one is removed.
Available in Mac OS X v10.6 and later.

NSFileManagerMBS.URLByResolvingSymlinksInPath(URL as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new URL that points to the same resource as the original URL and includes no symbolic links.

If the original URL has no symbolic links, the returned URL is identical to the original URL.

This method only works on URLs with the file: path scheme. This method will return an identical URL for all other URLs.

Available in Mac OS X v10.6 and later.

NSFileManagerMBS.URLByStandardizingPath(URL as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method iCloud MBS MacCocoa Plugin 12.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a new URL that points to the same resource as the original URL and is an absolute path.

This method only works on URLs with the file: path scheme. This method will return an identical URL for all other URLs.

Available in Mac OS X v10.6 and later.

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


The biggest plugin in space...