delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/01/02:07:07

Sender: nate AT cartsys DOT com
Message-ID: <37A3AFCF.D86385F6@cartsys.com>
Date: Sat, 31 Jul 1999 19:24:15 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.10 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: getting all filename in sub-directory
References: <7nliit$uvc$1 AT nnrp1 DOT deja DOT com>
Reply-To: djgpp AT delorie DOT com

chongkong AT my-deja DOT com wrote:
> 
> 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
> 
> but i really have no clue on how to go on and search all the sub-
> directory

How about the (also unportable, unfortunately):

glob_t g;
int i;
glob(".../*.ext", 0, NULL, &g);
for (i = 0; i < g.gl_pathc; i++)
	process_file(g.gl_pathv[i]);

Error handling is left as an exercise.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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