Finder Class Reference

 

Overview

The Finder class defines class methods that you can use to interact with the Finder in a limited fashion. It defines functions to select files, launch applications, open documents and URLs, and move/copy files. The description of the methods below is shown using an Objective-C like syntax and formatting to make things a bit more explicit (e.g. the usage of '+' to indicate class methods, as well as explicitly typing the arguments).

 

Finder Class Method List

The following methods are available in the Finder module:

 

Finder Class Method Descriptions

+ (BOOL)selectFile:(NSString *)aFile directory:(NSString *)aPath
Selects aFile in a Finder window. If aPath is non-nil, then a new Finder window is created rooted at the path aPath. If it is nil, then the main Finder window is used. Returns true if the operation was successful, false otherwise.

 

+ (BOOL)openFile:(NSString *)aFile withApplication:(NSString *)anApp
Asks the Finder to open aFile (which should be a fullpath to a file) using the application identified by anApp. anApp need not be a full path to an application, nor does it have to have the ".app" extension. Returns true if the operation was successful, false otherwise.

 

+ (BOOL)openURL:(NSString *)aUrl
Asks the Finder to open aURL. Returns true if the operation was successful, false otherwise. Note that you can specify any type of URL (e.g. a "mailto" url will open the user's mailer to send an email). Returns true if the operation was successful, false otherwise.

 

+ (BOOL)moveFiles:(NSArray *)someFiles fromDirectory:(NSString *)srcDir toDirectory:(NSString *)dstDir
Asks the Finder to move the files in the someFiles array from the source directory srcDir to the destination directory dstDir, both of which are specified as strings. Note that the filenames should be given relative to the source directory, and the destination directory must already exist. Returns true if the operation was successful, false otherwise.

 

+ (BOOL)copyFiles:(NSArray *)someFiles fromDirectory:(NSString *)srcDir toDirectory:(NSString *)dstDir
Asks the Finder to copy the files specified in the someFiles array from the source directory srcDir to the destination directory dstDir, both of which are specified as strings. Note that the filenames should be given relative to the source directory, and the destination directory must already exist. Returns true if the operation was successful, false otherwise.

 

+ (BOOL)recycleFiles:(NSArray *)someFiles inDirectory:(NSString *)srcDir
Asks the Finder to move the files specified in the someFiles array to the trash. The files should be given relative to the source directory srcDir. Returns true if the operation was successful, false otherwise.

 

+ (BOOL)deleteFiles:(NSArray *)someFiles inDirectory:(NSString *)srcDir
Asks the Finder to permanently delete the files specified in the someFiles array. The files should be given relative to the source directory srcDir. Returns true if the operation was successful, false otherwise. Note that this operation is immediate, and cannot be undone.

 

+ (BOOL)launchApplication:(NSString *)anApp
Asks the Finder to launch the application anApp. anApp does not have to be a full path, nor does it need the ".app" extension. Returns true if the operation was successful, false otherwise.