---
name: "for_each_file_ex"
section: "3alleg"
platform: "linux"
package: "liballegro-doc"
version: "2:4.2.2-2.2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/for_each_file_ex"
---

# for\_each\_file\_ex(3alleg)

Executes callback() for each file matching a wildcard. Allegro game programming library.

## NAME

for\_each\_file\_ex - Executes callback() for each file matching a wildcard. Allegro game programming library.

## SYNOPSIS

**#include \<allegro.h\>**

**int for\_each\_file\_ex(const char \*name, int in\_attrib, int out\_attrib,** **int (\*callback)(const char \*filename, int attrib,** **void \*param), void \*param);**

## DESCRIPTION

Finds all the files on disk which match the given wildcard specification and file attributes, and executes callback() once for each. Basically, this is a convenient wrapper around al\_findfirst(), al\_findnext() and al\_findclose(). \`in\_attrib' is a bitmask specifying the attributes the files must carry, \`out\_attrib' is a bitmask specifying the attributes the files must not carry; attributes which are not specified in either bitmasks are not taken into account for deciding whether callback() is invoked or not.

The callback function will be passed three arguments: the first is a string which contains the completed filename (exactly the same string you passed to for\_each\_file\_ex() but with meta characters), the second is the actual attributes of the file, and the third is a void pointer which is simply a copy of \`param' (you can use this for whatever you like). The callback must return zero to let the enumeration proceed, or any non-zero value to stop it. If an error occurs, the error code will be stored in \`errno' but the enumeration won't stop. Example:

```
   int show_name(const char *filename, int attrib, void *param)
   {
      allegro_message("Caught `%s', attribs %d\n",
                      filename, attrib);
      return 0;
   }
   ...
      count = for_each_file_ex("data/level*", FA_DIREC,
                               0, show_name, 0);
      allegro_message("%d game directories\n", count);
```

## RETURN VALUE

Returns the number of successful calls made to callback(), that is, the number of times callback() was called and returned 0.

## SEE ALSO

[**al\_findfirst**(3alleg)](/al_findfirst/3alleg.md), [**al\_findnext**(3alleg)](/al_findnext/3alleg.md), [**al\_findclose**(3alleg)](/al_findclose/3alleg.md)
