Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ walkdir(3) — GENIX 4.1A

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

directory(3S)

scandir(3)



      WALKDIR(3)              GENIX Programmer's Manual              WALKDIR(3)



      NAME
           walkdir - recursively find files in a directory hierarchy

      SYNOPSIS
           #include <sys/types.h>
           #include <dir.h>
           #include <stat.h>
           #include <walkdir.h>

           walkdir(startpath, calledroutine, flags)
           char *startpath;
           int (*calledroutine)();

           calledroutine(path, statbuf, error)
           char *path;
           struct stat *statbuf;

      DESCRIPTION
           Walkdir provides a way to examine all files downward  from  a  given
           file specification, by recursively examining directories and return-
           ing all file names found.  As  walkdir  finds  each  file  name,  it
           invokes  calledroutine,  supplying  the file name as the first argu-
           ment.

           Startpath is the path where the search  starts.   If  the  specified
           path  names  a file other than a directory, walkdir will return only
           that file's name.  If the path is a directory, then the names of all
           files  in  that  directory  will be returned, including those in all
           lower directories.  For example, to process the name of  every  file
           in the file system, startpath would be "/".

           Calledroutine is the user-defined routine which will be  called  for
           each  file  found.  It has three arguments.  Path is the path to the
           current file, and can be used to reference the found file.   Statbuf
           is  a  pointer  to the status of the file (see stat(2)).  Error is a
           flag indicating if the given file specification cannot be referenced
           (one common error is a directory that is unreadable).  Calledroutine
           should return zero to proceed to  the  next  file.   If  it  returns
           nonzero,  walkdir  will  abort the examination of the current direc-
           tory.  This can be used  to  skip  over  uninteresting  directories.
           Path  and  statbuf  are only valid during the call to calledroutine,
           and are overwritten between calls, so that they must  be  copied  if
           they are needed later.

           Flags specify the exact way in which the search is  to  take  place,
           and  consists  of  one  or  more of the following bits ORed together
           (defined in /usr/include/walkdir.h).

           #define SD_RETDIRF  0x01 /* return directories before files */
           #define SD_RETDIRL  0x02 /* return directories after files */
           #define SD_RETFILE  0x04 /* return files */
           #define SD_RETERR   0x08 /* return files with errors */



      Printed 11/16/83                                                        1





      WALKDIR(3)              GENIX Programmer's Manual              WALKDIR(3)



           #define SD_TYPERR   0x10 /* type error messages */

           To return directories, one of SD_RETDIRF or SD_RETDIRL must be  set.
           To return non-directories, SD_RETFILE must be set.  To have inacces-
           sible files returned, SD_RETERR must be set (if not set, error  does
           not  need  examination).   If  SD_TYPERR  is  set, then walkdir will
           automatically type error messages to standard error for inaccessible
           files.

      SEE ALSO
           directory(3S), scandir(3)

      DIAGNOSTICS
           Walkdir returns zero if all files were successfully examined.   Oth-
           erwise, it returns the number of inaccessible files, or -1 if start-
           path itself was inaccessible.







































      Printed 11/16/83                                                        2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026