Instance Method


Performs a file operation on a set of files in a particular directory.


- (BOOL)performFileOperation:(NSWorkspaceFileOperationName)operation source:(NSString *)source destination:(NSString *)destination files:(NSArray *)files tag:(NSInteger *)tag;



The file operation to perform. The possible values for this parameter are described in File Operations.


The full path to the directory containing the files on which to operate.


The full path to the destination directory of the operation.


An array of NSString objects specifying the names of the files and directories to be manipulated. Each string must not contain any path information other than the name of the file or directory. In other words, all of the files and directories must be located in the source directory and not in one if its subdirectories.


On input, a integer variable; on return, this variable contains a negative integer if the operation fails, 0 if the operation was performed synchronously and succeeded, or a positive integer if the operation was performed asynchronously. If the value is a positive integer, the value is a tag that identifies the requested file operation.

Return Value

YES if the operation succeeded; otherwise, NO.


Some operations—such as moving, copying, and linking files—require a destination directory to be specified. If not, destination should be the empty string (@""). Before this method returns, it posts an NSWorkspaceDidPerformFileOperationNotification to the NSWorkspace object's notification center.

It is safe to call this method from any thread of your app.

See Also

Manipulating Files

- duplicateURLs:completionHandler:

Duplicates the specified URLS asynchronously in the same manner as the Finder.

- recycleURLs:completionHandler:

Moves the specified URLs to the trash in the same manner as the Finder.

- activateFileViewerSelectingURLs:

Activates the Finder, and opens one or more windows selecting the specified files.

- selectFile:inFileViewerRootedAtPath:

Selects the file specified by fullPath.


These constants specify different types of file operations used by performFileOperation:source:destination:files:tag:.

File Types

These constants specify different types of files returned by the getInfoForFile:application:type: method.