home *** CD-ROM | disk | FTP | other *** search
- This example shows you how to "walk" through all the files in a directory
- or series of directory, including any subdirectories. "dirwalker.c"
- provides a function called "dirwalker" which will visit all the files and
- directories in a tree, calling a function you provide for each one.
-
- The use of dirwalker() is as follows:
-
- #include "dirwalker.h"
-
- rc = dirwalker(dirname, dirfunc, filefunc);
-
- Where
-
- rc is the integer return code. -1 indicates that your callback
- function returned a nonzero return value, 0 indicates success,
- and anything else is an AmigaDOS error code.
-
- dirname is the name of the directory to walk. dirname should be a
- char * pointing to the name. If NULL is passed, the current
- directory is taken as the starting point.
-
- dirfunc is the function to be called when a new directory is
- encountered. If you pass NULL, no action is taken when a
- new directory is encountered, but directories are still
- traversed for files. If you return a nonzero return value,
- the traversal is aborted.
-
- filefunc is the function to be called when a new file is encountered.
- If you pass NULL, no action is taken when a new file is
- encountered. If you return a nonzero return value, the
- traversal is aborted.
-
- "filefunc" and "dirfunc" both return an integer and take two character
- pointers as parameters. The first character pointer points to the name
- of the parent directory of the file or directory, and the second points
- to the name of the file or directory itself. Look at the source code
- "show.c" or "sword.c" for more information.
-
- Two example programs are provided that use "dirwalker.c". You can build
- both simply by double-clicking the Build icon or by typing "smake" in
- the Shell. The programs do the following:
-
- show [dir]
-
- Prints all files and directories to stdout. Basically, a do-nothing
- very simple example of how to use dirwalker().
-
- sword <word> [dir]
-
- Searches all text files in the directory tree starting with [dir]
- for <word>. Uses the AmigaDOS SEARCH command.
-
-