listfiles(
FOLDER
,
FILTER
)

The listfiles( function builds a text array listing the files in a folder.


Parameters

This function has two parameters:

folder – the path to the folder. See Files and Folders for details about file paths.

filter – is a text item that specifies what type (or types) of files (and folders) to list. If this is an empty text item (""), or if this parameter is omitted, all files and folders will be listed.

To specify that only specific types of files should be included in the list, this parameter must include a list of the file extensions to be included. See the description below for details.


Description

This function builds a text array listing the files in a folder. The items in the list are separated by the carriage return character (see Text Arrays). The second parameter, filter, controls which files are included in the list.

If the filter is empty, all files and folders are listed. For example, this formula will list all files and all folders in the Documents folder.

listfiles("~/Documents","")

To list only a specific type of file, put the file extension in the filter parameter. For example, this formula will list only text files in the Documents folder (no folders will be listed).

listfiles("~/Documents",".txt")

To include multiple file types in the list simply list all of the extensions to be included. This example will list various types of image files in the Pictures folder.

listfiles("~/Pictures",".jpg.jpeg.png.gif.tif.tiff")

To list all files, but no folders, use

.*

This example will list all files in the Movies folder (no folders will be listed).

listfiles("~/Movies",".*")

Note: You can also use just * instead of .*

To list folders as well as files, insert the ƒ (Option-F) character at the beginning of the filter This example will list all web source documents in the Documents folder, along with any subfolders of the Documents folder.

listfiles("~/Documents","ƒ.html.css")

To list only folders, it’s necessary to include a trailing period.

listfiles("~/Documents","ƒ.")
Legacy Support for Type/Creator Codes

In previous versions of Panorama the filter parameter used type/creator codes (see the typecreatorcode( function) instead of file extensions. For compatibility with older databases, Panorama continues to support these codes. New databases should use the file extension method described above.

Note: Current versions of Panorama do not actually check the file’s OS 9 type and creator codes (most files in OS X do not have these codes any more). Instead Panorama uses the file’s extension to synthesize the type and creator codes. The current version of Panorama requires that all files it works with have an extension, files without an extension will be ignored by the listfiles( function (unless you tell it to list all files).


Error Messages

listfiles( function error, folder does not exist. – The folder parameter must be a valid folder path, if not, this error message will appear.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0, but now supports file extensions in addition to type/creator codes.