Home Contents | # filer:lookup | Filer | Core4 Lua Commands

## SYNOPSIS

1. path = filer:lookup(file[, lang | nil[, subdir]])
2. table = filer:list(file[, lang | nil][, subdir])

## DESCRIPTION

This searches for the file named file using the lookup rules that the filer was configured for.

If file is a relative path, it is tried subsequently on each entry in the filer.path list.

When an absolute path was given for file, it is also subsequently verified against each entry in the path list, to make sure that the file name is permitted.

If lang is not given, the value from filer.lang is used instead (which may be nil). To explicitly forbid using a language subdirectory even if filer.lang is set, pass an empty string as the language.

Each full path tried is made up from the following components:

(path)/(subdir)/(lang)/(file)

Where:

(path) | is one of the entries in the filer.path list.
(subdir) | is made from filer.subdir and the optional subdir parameter. If both are not set, the (subdir) part is completely left out. If both are set, they are concatenated with a '/' inbetween, with filer.subdir being first.
(lang) | is the language name.
(file) | is the filename passed to this function.

If a language was used and no file was found, a second round is made over the path, this time with the language removed. The idea is to provide language specific files, but fall back to a generic set if there is no file for that language.

## RETURN VALUE

filer:lookup() returns the full path of the file. It returns nil if the file could not be found or if a passed absolute path did not match any of the configured paths.

filer:list() returns a table with all files matching the call. It returns nil if no file could be found or if a passed absolute path did not match any of the configured paths.

## NOTES

filer:list() does multiple passes across the file system. This may be slow. Use filer.lookup() instead if possible.

## EXAMPLE

The following code assumes a filer instance that was initialized as per example on the introduction page.

This example finds the file in the german language subdirectory:

>
print (f:lookup("textlist.csv", "deu"))
/usr/share/app/deu/textlist.csv

The next example falls back to the generic, language independent path, since there seems to be no ancient greek language file present:

>
print (f:lookup("textlist.csv", "grc"))
/usr/share/app/textlist.csv

The following prints nil because the absolute path given is not in the f.path list and thus rejected.

>
print (f:lookup("/etc/inittab"))
nil

## SEE ALSO

filer.new, filer:cleanup