filecatalog(
ROOTPATH
,
PATTERN
,
OPTION
,
VALUE
)

The filecatalog( function builds a text array listing the files in a folder, including any subfolders of that folder.


Parameters

This function has four parameters:

rootpath – path of the folder to be cataloged. This may be in either UNIX or HFS format.

pattern – wildcard pattern which may contain * and ? for matching file and folder names. This parameter is optional. Note: If this parameter starts with a period, it is treated as a list of file extensions.

option – this and the following parameter are optional, and may also be repeated. It specifies an option for modifying the operation of the filecatalog( function. See the text below for details.

value – value of the option.


Description

This function builds a text array listing the files in a folder, including any subfolders of that folder. If only one parameter is supplied, the function will list every file inside the specified folder. This example will return a list of every file inside your Dropbox folder:

filecatalog("~/Dropbox")

You can add a second parameter to list only files that match a wildcard pattern. This example lists only files that contain the word baby (the word baby may be in either the filename or in the name of any folder enclosing the file).

filecatalog("~/Dropbox","*baby*")

If the pattern starts with a period, it specifies a list of file extensions that will match (when doing this you cannot use the * and ? wildcard characters). This example lists all of the image files in your Dropbox folder.

filecatalog("~/Dropbox",".jpg.png.gif")

Option/Value Pairs

You can add one or more option/value pairs to the function to modify how the list of files is collected. These option/value pairs can be used with or witout a pattern as the second parameter (you can also specify patterns using an option/value pair, as described below).

filecatalog(root,option,value,option,value ... option,value)
filecatalog(root,pattern,option,value,option,value ... option,value)

The avilable options are: wildcard, extensions, typecreator, hfs, hidden and insidepackages. Each of these options are described in detail below.

Wildcard

This option sets up a wildcard pattern using the * and ? wildcard characters. This example lists files that are related to holidays (or at least contain holidays in the file or folder name).

filecatalog("~/Dropbox","wildcard","*holiday*)

Extensions

This option allows you to specify a list of file extensions to include in the list. This example will include several different types of image files:

filecatalog("~/Dropbox","extensions",".jpg.jpeg.png.gif.tif.tiff)

Note: you can combine wildcard and extension options, for example to list baby pictures.

Type/Creator Codes

This option allows you to specify what types of files to list by using the old “Mac OS” type/creator codes. This example lists all text files inside the Dropbox folder.

filecatalog("~/Dropbox","TEXT????")

For new applications we recommend using the Extensions option rather than the Type/Creator codes. Note: You can only use one of these options at a time, you cannot use TypeCreator and Extensions together in the same function.

HFS

The filecatalog( function normally generates the list of files in UNIX format, like this:

/Users/bobsmith/Dropbox/Photos/Baby/Photo Jun 17, 10 05 40 AM.jpg
/Users/bobsmith/Dropbox/Photos/Baby/Photo Jun 17, 10 05 43 AM.jpg
/Users/bobsmith/Dropbox/Photos/Baby/Photo Jun 17, 10 05 53 AM.jpg
/Users/bobsmith/Dropbox/Photos/Baby/Photo Jun 17, 10 05 57 AM.jpg

By setting the HFS option to true:

filecatalog("~/Dropbox","extensions",".jpg","hfs","true")

the result will be in HFS format (the old format used by Mac OS before OS X):

Mercury HD:Users:bobsmith:Dropbox:Photos:Baby:Photo Jun 17, 10 05 40 AM.jpg
Mercury HD:Users:bobsmith:Dropbox:Photos:Baby:Photo Jun 17, 10 05 43 AM.jpg
Mercury HD:Users:bobsmith:Dropbox:Photos:Baby:Photo Jun 17, 10 05 53 AM.jpg
Mercury HD:Users:bobsmith:Dropbox:Photos:Baby:Photo Jun 17, 10 05 57 AM.jpg

This format can be useful if you have old code that was written to use HFS format.

Note: If the rootpath is specified in HFS format, the result will default to HFS format instead of UNIX format. However, you can always override the default by explicitly setting the HFS option to true or false.

Hidden

The filecatalog( function normally doesn’t include hidden (invisible) files. Set this option to true if you do want them listed.

filecatalog("~/Dropbox","hidden","true")

InsidePackages

The filecatalog( function normally doesn’t include files that are inside packages. Set this option to true if you do want these files included. (If you don’t know what a package is, just leave this option turned off.)


See Also


History

VersionStatusNotes
10.0NewNew in this version.