Home Contents | # Introduction | Filer | Core4 Lua Commands

## DESCRIPTION

The filer is a class for doing filename lookups on a search path.

After creating a new instance with filer.new, it must be initialized with a searchpath and an optional shortcut table.

Files can be searched by calling filer:lookup(). The filer also supports an additional language parameter, which looks for files in a subdirectory of each path component with that name.

Calling filer:cleanup() verifies if the passed filename lies within one of the searchpaths that where configured. This is used to constrain filenames to certain paths.

## EXAMPLE

The following is an example initialization of a filer instance. When a filer looks up a filename, it walks the f.path table from top to bottom until the file is found.

If the optional value f.subdir is given, it is implicitly appended to the end of each path in f.path when doing file lookups.

The optional f.shortcuts table allows to use a drive letter style shortcut for each path component. Given the example below, passing mmc:/test.txt would expand to /media/mmc0a/app/test.txt.

> > > > > > > > > > > > > > > > > > >
f = filer.new() f.path = { "/media/tmp", "/media/mmc0a", "/media/df0b", "/media/nand0a", "/usr/share", } f.shortcuts = { "tmp:", "mmc:", "df:", "nand:", "rom:", } f.subdir = "app"

After this initialization, the following call to filer:lookup

>
abspath = f:lookup("textlist.csv", "eng")

will try the files in the following order, until a match is found:

/media/tmp/app/eng/textlist.csv /media/mmc0a/app/eng/textlist.csv /media/df0b/app/eng/textlist.csv /media/nand0a/app/eng/textlist.csv /usr/share/app/eng/textlist.csv /media/tmp/app/textlist.csv /media/mmc0a/app/textlist.csv /media/df0b/app/textlist.csv /media/nand0a/app/textlist.csv /usr/share/app/textlist.csv

Note how the language specific paths are tried first, before the generic paths are checked.

## SEE ALSO

filer.new, filer:cleanup, filer:lookup