cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/28/16:50:26

From: "Michael Stewart" <mike AT reggin DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: getting all filename in sub-directory
Date: Wed, 28 Jul 1999 09:18:38 +0100
Organization: (Posted via) Netcom Internet Ltd.
Message-ID: <7nmecv$d5c$1@taliesin.netcom.net.uk>
References: <7nliit$uvc$1 AT nnrp1 DOT deja DOT com>
NNTP-Posting-Host: hgty.capgemini.co.uk
X-Trace: taliesin.netcom.net.uk 933149919 13484 194.42.240.2 (28 Jul 1999 08:18:39 GMT)
X-Complaints-To: abuse AT corp DOT netcom DOT net DOT uk
NNTP-Posting-Date: 28 Jul 1999 08:18:39 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3155.0
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
Lines: 47
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

chongkong AT my-deja DOT com wrote in message <7nliit$uvc$1 AT nnrp1 DOT deja DOT com>...
>is there any sample code to do a recursive process for file of a
>certain extension from a parent directory and its sub-directory?
>
>i thinking of using system("dir > tmpfilename")
>and then checking tmpfilename.

>or is there a much better way


There certainly is :-)

>but i really have no clue on how to go on and search all the sub-
>directory


From the libc reference:

#include <dir.h>

int __file_tree_walk(const char *dir, int (*func)(const char *path, const
struct ffblk *ff));

This function recursively descends the directory hierarchy which starts with
dir.  For each file in the hierarchy, `__file_tree_walk' calls the
user-defined function func which is passed a pointer to a `NULL'-terminated
character array in path holding the full pathname of the file, a pointer to
a `ffblk' structure (see findfirst) fff with a DOS filesystem information
about that file.

This function always visits a directory before any of its siblings.  The
argument dir must be a directory, or `__file_tree_walk' will fail and set
errno to `ENOTDIR'.  The directory dir itself is never passed to func.

The tree traversal continues until one of the following events:

(1)  The tree is exhausted (i.e., all descendants of dir are processed).  In
this case, `__file_tree_walk' returns 0, meaning a success.

(2)  An invocation of func returns a non-zero value.  In this case,
`__file_tree_walk' stops the tree traversal and returns whatever func
returned.

(3)  An error is detected within `__file_tree_walk'.  In that case, `ftw'
returns -1 and sets errno (see errno) to a suitable value.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019