A Find Utility

As a final example, we’ll use file:list_dir and file:read_file_info to make a general-purpose “find” utility.

The main entry point to this module is as follows:

 
lib_find:files(Dir, RegExp, Recursive, Fun, Acc0)

The arguments are as follows:

Dir

The directory name to start the file search in.

RegExp

A shell-style regular expression to test the files we have found. If the files we encounter match this regular expression, then Fun(File, Acc) will be called, where File is the name of the file that matches the regular expression.

Recursive = true | false

A flag that determines whether search should recurse into the subdirectories of the current directory in the search path.

Fun(File, AccIn) -> AccOut

A function that is applied to the ...

Get Programming Erlang, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.