1fts(3) Library Functions Manual fts(3)
2
3
4
6 fts, fts_open, fts_read, fts_children, fts_set, fts_close - traverse a
7 file hierarchy
8
10 Standard C library (libc, -lc)
11
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fts.h>
16
17 FTS *fts_open(char * const *path_argv, int options,
18 int (*compar)(const FTSENT **, const FTSENT **));
19
20 FTSENT *fts_read(FTS *ftsp);
21
22 FTSENT *fts_children(FTS *ftsp, int instr);
23
24 int fts_set(FTS *ftsp, FTSENT *f, int instr);
25
26 int fts_close(FTS *ftsp);
27
29 The fts functions are provided for traversing file hierarchies. A sim‐
30 ple overview is that the fts_open() function returns a "handle" (of
31 type FTS *) that refers to a file hierarchy "stream". This handle is
32 then supplied to the other fts functions. The function fts_read() re‐
33 turns a pointer to a structure describing one of the files in the file
34 hierarchy. The function fts_children() returns a pointer to a linked
35 list of structures, each of which describes one of the files contained
36 in a directory in the hierarchy.
37
38 In general, directories are visited two distinguishable times; in pre‐
39 order (before any of their descendants are visited) and in postorder
40 (after all of their descendants have been visited). Files are visited
41 once. It is possible to walk the hierarchy "logically" (visiting the
42 files that symbolic links point to) or physically (visiting the sym‐
43 bolic links themselves), order the walk of the hierarchy or prune
44 and/or revisit portions of the hierarchy.
45
46 Two structures (and associated types) are defined in the include file
47 <fts.h>. The first type is FTS, the structure that represents the file
48 hierarchy itself. The second type is FTSENT, the structure that repre‐
49 sents a file in the file hierarchy. Normally, an FTSENT structure is
50 returned for every file in the file hierarchy. In this manual page,
51 "file" and "FTSENT structure" are generally interchangeable.
52
53 The FTSENT structure contains fields describing a file. The structure
54 contains at least the following fields (there are additional fields
55 that should be considered private to the implementation):
56
57 typedef struct _ftsent {
58 unsigned short fts_info; /* flags for FTSENT structure */
59 char *fts_accpath; /* access path */
60 char *fts_path; /* root path */
61 short fts_pathlen; /* strlen(fts_path) +
62 strlen(fts_name) */
63 char *fts_name; /* filename */
64 short fts_namelen; /* strlen(fts_name) */
65 short fts_level; /* depth (-1 to N) */
66 int fts_errno; /* file errno */
67 long fts_number; /* local numeric value */
68 void *fts_pointer; /* local address value */
69 struct _ftsent *fts_parent; /* parent directory */
70 struct _ftsent *fts_