home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / extras / dirwalker / READ.ME < prev    next >
Encoding:
Text File  |  1996-12-24  |  2.1 KB  |  53 lines

  1. This example shows you how to "walk" through all the files in a directory
  2. or series of directory, including any subdirectories.  "dirwalker.c" 
  3. provides a function called "dirwalker" which will visit all the files and
  4. directories in a tree, calling a function you provide for each one.
  5.  
  6. The use of dirwalker() is as follows:
  7.  
  8.    #include "dirwalker.h"
  9.  
  10.    rc = dirwalker(dirname, dirfunc, filefunc);
  11.  
  12. Where
  13.  
  14.    rc       is the integer return code.  -1 indicates that your callback
  15.             function returned a nonzero return value, 0 indicates success,
  16.             and anything else is an AmigaDOS error code.
  17.  
  18.    dirname  is the name of the directory to walk.  dirname should be a
  19.             char * pointing to the name.  If NULL is passed, the current
  20.             directory is taken as the starting point.
  21.  
  22.    dirfunc  is the function to be called when a new directory is 
  23.             encountered.  If you pass NULL, no action is taken when a
  24.             new directory is encountered, but directories are still
  25.             traversed for files.  If you return a nonzero return value,
  26.             the traversal is aborted.
  27.  
  28.    filefunc is the function to be called when a new file is encountered.
  29.             If you pass NULL, no action is taken when a new file is
  30.             encountered.  If you return a nonzero return value, the
  31.             traversal is aborted.
  32.  
  33. "filefunc" and "dirfunc" both return an integer and take two character
  34. pointers as parameters.  The first character pointer points to the name
  35. of the parent directory of the file or directory, and the second points
  36. to the name of the file or directory itself.  Look at the source code
  37. "show.c" or "sword.c" for more information.
  38.  
  39. Two example programs are provided that use "dirwalker.c".  You can build
  40. both simply by double-clicking the Build icon or by typing "smake" in
  41. the Shell.  The programs do the following:
  42.  
  43.    show [dir] 
  44.    
  45.       Prints all files and directories to stdout.  Basically, a do-nothing
  46.       very simple example of how to use dirwalker().
  47.  
  48.    sword <word> [dir]
  49.    
  50.       Searches all text files in the directory tree starting with [dir]
  51.       for <word>.  Uses the AmigaDOS SEARCH command.
  52.  
  53.